Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: net/cert/jwk_serializer_unittest.cc

Issue 65353002: Update JWK output to match latest draft (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/cert/jwk_serializer_nss.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/cert/jwk_serializer.h" 5 #include "net/cert/jwk_serializer.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 base::DictionaryValue public_key_jwk; 68 base::DictionaryValue public_key_jwk;
69 69
70 EXPECT_FALSE(JwkSerializer::ConvertSpkiFromDerToJwk(spki, &public_key_jwk)); 70 EXPECT_FALSE(JwkSerializer::ConvertSpkiFromDerToJwk(spki, &public_key_jwk));
71 EXPECT_TRUE(public_key_jwk.empty()); 71 EXPECT_TRUE(public_key_jwk.empty());
72 72
73 // Test the result of a "normal" point on this curve. 73 // Test the result of a "normal" point on this curve.
74 spki.set(reinterpret_cast<const char*>(kSpkiEc), sizeof(kSpkiEc)); 74 spki.set(reinterpret_cast<const char*>(kSpkiEc), sizeof(kSpkiEc));
75 EXPECT_TRUE(JwkSerializer::ConvertSpkiFromDerToJwk(spki, &public_key_jwk)); 75 EXPECT_TRUE(JwkSerializer::ConvertSpkiFromDerToJwk(spki, &public_key_jwk));
76 76
77 std::string string_value; 77 std::string string_value;
78 EXPECT_TRUE(public_key_jwk.GetString("alg", &string_value)); 78 EXPECT_TRUE(public_key_jwk.GetString("kty", &string_value));
79 EXPECT_STREQ("EC", string_value.c_str()); 79 EXPECT_STREQ("EC", string_value.c_str());
80 EXPECT_TRUE(public_key_jwk.GetString("crv", &string_value)); 80 EXPECT_TRUE(public_key_jwk.GetString("crv", &string_value));
81 EXPECT_STREQ("P-256", string_value.c_str()); 81 EXPECT_STREQ("P-256", string_value.c_str());
82 82
83 EXPECT_TRUE(public_key_jwk.GetString("x", &string_value)); 83 EXPECT_TRUE(public_key_jwk.GetString("x", &string_value));
84 std::string decoded_coordinate; 84 std::string decoded_coordinate;
85 EXPECT_TRUE(base::Base64Decode(string_value, &decoded_coordinate)); 85 EXPECT_TRUE(base::Base64Decode(string_value, &decoded_coordinate));
86 EXPECT_EQ(kEcCoordinateSize, decoded_coordinate.size()); 86 EXPECT_EQ(kEcCoordinateSize, decoded_coordinate.size());
87 EXPECT_EQ(0, 87 EXPECT_EQ(0,
88 memcmp(decoded_coordinate.data(), 88 memcmp(decoded_coordinate.data(),
89 kSpkiEc + sizeof(kP256SpkiPrefix), 89 kSpkiEc + sizeof(kP256SpkiPrefix),
90 kEcCoordinateSize)); 90 kEcCoordinateSize));
91 91
92 EXPECT_TRUE(public_key_jwk.GetString("y", &string_value)); 92 EXPECT_TRUE(public_key_jwk.GetString("y", &string_value));
93 EXPECT_TRUE(base::Base64Decode(string_value, &decoded_coordinate)); 93 EXPECT_TRUE(base::Base64Decode(string_value, &decoded_coordinate));
94 EXPECT_EQ(kEcCoordinateSize, decoded_coordinate.size()); 94 EXPECT_EQ(kEcCoordinateSize, decoded_coordinate.size());
95 EXPECT_EQ(0, 95 EXPECT_EQ(0,
96 memcmp(decoded_coordinate.data(), 96 memcmp(decoded_coordinate.data(),
97 kSpkiEc + sizeof(kP256SpkiPrefix) + kEcCoordinateSize, 97 kSpkiEc + sizeof(kP256SpkiPrefix) + kEcCoordinateSize,
98 kEcCoordinateSize)); 98 kEcCoordinateSize));
99 99
100 // Test the result of a corner case: leading 0s in the x, y coordinates are 100 // Test the result of a corner case: leading 0s in the x, y coordinates are
101 // not trimmed, but the point is fixed-length encoded. 101 // not trimmed, but the point is fixed-length encoded.
102 spki.set(reinterpret_cast<const char*>(kSpkiEcWithZeroXY), 102 spki.set(reinterpret_cast<const char*>(kSpkiEcWithZeroXY),
103 sizeof(kSpkiEcWithZeroXY)); 103 sizeof(kSpkiEcWithZeroXY));
104 EXPECT_TRUE(JwkSerializer::ConvertSpkiFromDerToJwk(spki, &public_key_jwk)); 104 EXPECT_TRUE(JwkSerializer::ConvertSpkiFromDerToJwk(spki, &public_key_jwk));
105 105
106 EXPECT_TRUE(public_key_jwk.GetString("alg", &string_value)); 106 EXPECT_TRUE(public_key_jwk.GetString("kty", &string_value));
107 EXPECT_STREQ("EC", string_value.c_str()); 107 EXPECT_STREQ("EC", string_value.c_str());
108 EXPECT_TRUE(public_key_jwk.GetString("crv", &string_value)); 108 EXPECT_TRUE(public_key_jwk.GetString("crv", &string_value));
109 EXPECT_STREQ("P-256", string_value.c_str()); 109 EXPECT_STREQ("P-256", string_value.c_str());
110 110
111 EXPECT_TRUE(public_key_jwk.GetString("x", &string_value)); 111 EXPECT_TRUE(public_key_jwk.GetString("x", &string_value));
112 EXPECT_TRUE(base::Base64Decode(string_value, &decoded_coordinate)); 112 EXPECT_TRUE(base::Base64Decode(string_value, &decoded_coordinate));
113 EXPECT_EQ(kEcCoordinateSize, decoded_coordinate.size()); 113 EXPECT_EQ(kEcCoordinateSize, decoded_coordinate.size());
114 EXPECT_EQ(0, 114 EXPECT_EQ(0,
115 memcmp(decoded_coordinate.data(), 115 memcmp(decoded_coordinate.data(),
116 kSpkiEcWithZeroXY + sizeof(kP256SpkiPrefix), 116 kSpkiEcWithZeroXY + sizeof(kP256SpkiPrefix),
(...skipping 23 matching lines...) Expand all
140 // but even a valid SPKI is non-convertible via the stub OpenSSL 140 // but even a valid SPKI is non-convertible via the stub OpenSSL
141 // implementation. 141 // implementation.
142 spki.set(reinterpret_cast<const char*>(kSpkiEc), sizeof(kSpkiEc)); 142 spki.set(reinterpret_cast<const char*>(kSpkiEc), sizeof(kSpkiEc));
143 EXPECT_FALSE(JwkSerializer::ConvertSpkiFromDerToJwk(spki, &public_key_jwk)); 143 EXPECT_FALSE(JwkSerializer::ConvertSpkiFromDerToJwk(spki, &public_key_jwk));
144 EXPECT_TRUE(public_key_jwk.empty()); 144 EXPECT_TRUE(public_key_jwk.empty());
145 } 145 }
146 146
147 #endif // !defined(USE_OPENSSL) 147 #endif // !defined(USE_OPENSSL)
148 148
149 } // namespace net 149 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/jwk_serializer_nss.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698