OLD | NEW |
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 <cert.h> | 7 #include <cert.h> |
8 #include <keyhi.h> | 8 #include <keyhi.h> |
9 #include <nss.h> | 9 #include <nss.h> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 CERTSubjectPublicKeyInfo* spki, | 23 CERTSubjectPublicKeyInfo* spki, |
24 base::DictionaryValue* public_key_jwk) { | 24 base::DictionaryValue* public_key_jwk) { |
25 static const int kUncompressedEncodingType = 4; | 25 static const int kUncompressedEncodingType = 4; |
26 static const int kPrime256v1PublicKeyLength = 64; | 26 static const int kPrime256v1PublicKeyLength = 64; |
27 // The public key value is encoded as 0x04 + 64 bytes of public key. | 27 // The public key value is encoded as 0x04 + 64 bytes of public key. |
28 // NSS gives the length as the bit length. | 28 // NSS gives the length as the bit length. |
29 if (spki->subjectPublicKey.len != (kPrime256v1PublicKeyLength + 1) * 8 || | 29 if (spki->subjectPublicKey.len != (kPrime256v1PublicKeyLength + 1) * 8 || |
30 spki->subjectPublicKey.data[0] != kUncompressedEncodingType) | 30 spki->subjectPublicKey.data[0] != kUncompressedEncodingType) |
31 return false; | 31 return false; |
32 | 32 |
33 public_key_jwk->SetString("alg", "EC"); | 33 public_key_jwk->SetString("kty", "EC"); |
34 public_key_jwk->SetString("crv", "P-256"); | 34 public_key_jwk->SetString("crv", "P-256"); |
35 | 35 |
36 base::StringPiece x( | 36 base::StringPiece x( |
37 reinterpret_cast<char*>(spki->subjectPublicKey.data + 1), | 37 reinterpret_cast<char*>(spki->subjectPublicKey.data + 1), |
38 kPrime256v1PublicKeyLength / 2); | 38 kPrime256v1PublicKeyLength / 2); |
39 std::string x_b64; | 39 std::string x_b64; |
40 base::Base64Encode(x, &x_b64); | 40 base::Base64Encode(x, &x_b64); |
41 public_key_jwk->SetString("x", x_b64); | 41 public_key_jwk->SetString("x", x_b64); |
42 | 42 |
43 base::StringPiece y( | 43 base::StringPiece y( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 sizeof(kIdEcPublicKey))) { | 109 sizeof(kIdEcPublicKey))) { |
110 rv = ConvertEcPublicKeyInfoToJwk(spki.get(), public_key_jwk); | 110 rv = ConvertEcPublicKeyInfoToJwk(spki.get(), public_key_jwk); |
111 } | 111 } |
112 // TODO(juanlang): other algorithms | 112 // TODO(juanlang): other algorithms |
113 return rv; | 113 return rv; |
114 } | 114 } |
115 | 115 |
116 } // namespace JwkSerializer | 116 } // namespace JwkSerializer |
117 | 117 |
118 } // namespace net | 118 } // namespace net |
OLD | NEW |