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

Side by Side Diff: base/crypto/rsa_private_key.h

Issue 307009: Add a comment warning against using RSAPrivateKeyImport on untrusted sources. (Closed)
Patch Set: Created 11 years, 2 months 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 | « no previous file | 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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef BASE_CRYPTO_RSA_PRIVATE_KEY_H_ 5 #ifndef BASE_CRYPTO_RSA_PRIVATE_KEY_H_
6 #define BASE_CRYPTO_RSA_PRIVATE_KEY_H_ 6 #define BASE_CRYPTO_RSA_PRIVATE_KEY_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #if defined(USE_NSS) 10 #if defined(USE_NSS)
(...skipping 21 matching lines...) Expand all
32 32
33 // ASN.1 encoding of the AlgorithmIdentifier from PKCS #8. 33 // ASN.1 encoding of the AlgorithmIdentifier from PKCS #8.
34 static const uint8 kRsaAlgorithmIdentifier[]; 34 static const uint8 kRsaAlgorithmIdentifier[];
35 35
36 // ASN.1 tags for some types we use. 36 // ASN.1 tags for some types we use.
37 static const uint8 kBitStringTag = 0x03; 37 static const uint8 kBitStringTag = 0x03;
38 static const uint8 kIntegerTag = 0x02; 38 static const uint8 kIntegerTag = 0x02;
39 static const uint8 kNullTag = 0x05; 39 static const uint8 kNullTag = 0x05;
40 static const uint8 kOctetStringTag = 0x04; 40 static const uint8 kOctetStringTag = 0x04;
41 static const uint8 kSequenceTag = 0x30; 41 static const uint8 kSequenceTag = 0x30;
42 42
43 // |big_endian| here specifies the byte-significance of the integer components 43 // |big_endian| here specifies the byte-significance of the integer components
44 // that will be parsed & serialized (modulus(), etc...) during Import(), 44 // that will be parsed & serialized (modulus(), etc...) during Import(),
45 // Export() and ExportPublicKeyInfo() -- not the ASN.1 DER encoding of the 45 // Export() and ExportPublicKeyInfo() -- not the ASN.1 DER encoding of the
46 // PrivateKeyInfo/PublicKeyInfo (which is always big-endian). 46 // PrivateKeyInfo/PublicKeyInfo (which is always big-endian).
47 explicit PrivateKeyInfoCodec(bool big_endian) : big_endian_(big_endian) {} 47 explicit PrivateKeyInfoCodec(bool big_endian) : big_endian_(big_endian) {}
48 48
49 // Exports the contents of the integer components to the ASN.1 DER encoding 49 // Exports the contents of the integer components to the ASN.1 DER encoding
50 // of the PrivateKeyInfo structure to |output|. 50 // of the PrivateKeyInfo structure to |output|.
51 bool Export(std::vector<uint8>* output); 51 bool Export(std::vector<uint8>* output);
52 52
53 // Exports the contents of the integer components to the ASN.1 DER encoding 53 // Exports the contents of the integer components to the ASN.1 DER encoding
54 // of the PublicKeyInfo structure to |output|. 54 // of the PublicKeyInfo structure to |output|.
55 bool ExportPublicKeyInfo(std::vector<uint8>* output); 55 bool ExportPublicKeyInfo(std::vector<uint8>* output);
56 56
57 // Parses the ASN.1 DER encoding of the PrivateKeyInfo structure in |input| 57 // Parses the ASN.1 DER encoding of the PrivateKeyInfo structure in |input|
58 // and populates the integer components with |big_endian_| byte-significance. 58 // and populates the integer components with |big_endian_| byte-significance.
59 // IMPORTANT NOTE: This is currently *not* security-approved for importing
60 // keys from unstrusted sources.
59 bool Import(const std::vector<uint8>& input); 61 bool Import(const std::vector<uint8>& input);
60 62
61 // Accessors to the contents of the integer components of the PrivateKeyInfo 63 // Accessors to the contents of the integer components of the PrivateKeyInfo
62 // structure. 64 // structure.
63 std::vector<uint8>* modulus() { return &modulus_; }; 65 std::vector<uint8>* modulus() { return &modulus_; };
64 std::vector<uint8>* public_exponent() { return &public_exponent_; }; 66 std::vector<uint8>* public_exponent() { return &public_exponent_; };
65 std::vector<uint8>* private_exponent() { return &private_exponent_; }; 67 std::vector<uint8>* private_exponent() { return &private_exponent_; };
66 std::vector<uint8>* prime1() { return &prime1_; }; 68 std::vector<uint8>* prime1() { return &prime1_; };
67 std::vector<uint8>* prime2() { return &prime2_; }; 69 std::vector<uint8>* prime2() { return &prime2_; };
68 std::vector<uint8>* exponent1() { return &exponent1_; }; 70 std::vector<uint8>* exponent1() { return &exponent1_; };
69 std::vector<uint8>* exponent2() { return &exponent2_; }; 71 std::vector<uint8>* exponent2() { return &exponent2_; };
70 std::vector<uint8>* coefficient() { return &coefficient_; }; 72 std::vector<uint8>* coefficient() { return &coefficient_; };
71 73
72 private: 74 private:
73 // Utility wrappers for PrependIntegerImpl that use the class's |big_endian_| 75 // Utility wrappers for PrependIntegerImpl that use the class's |big_endian_|
74 // value. 76 // value.
75 void PrependInteger(const std::vector<uint8>& in, std::list<uint8>* out); 77 void PrependInteger(const std::vector<uint8>& in, std::list<uint8>* out);
76 void PrependInteger(uint8* val, int num_bytes, std::list<uint8>* data); 78 void PrependInteger(uint8* val, int num_bytes, std::list<uint8>* data);
77 79
78 // Prepends the integer stored in |val| - |val + num_bytes| with |big_endian| 80 // Prepends the integer stored in |val| - |val + num_bytes| with |big_endian|
79 // byte-significance into |data| as an ASN.1 integer. 81 // byte-significance into |data| as an ASN.1 integer.
80 void PrependIntegerImpl(uint8* val, 82 void PrependIntegerImpl(uint8* val,
81 int num_bytes, 83 int num_bytes,
82 std::list<uint8>* data, 84 std::list<uint8>* data,
83 bool big_endian); 85 bool big_endian);
84 86
85 // Utility wrappers for ReadIntegerImpl that use the class's |big_endian_| 87 // Utility wrappers for ReadIntegerImpl that use the class's |big_endian_|
86 // value. 88 // value.
87 bool ReadInteger(uint8** pos, uint8* end, std::vector<uint8>* out); 89 bool ReadInteger(uint8** pos, uint8* end, std::vector<uint8>* out);
88 bool ReadIntegerWithExpectedSize(uint8** pos, 90 bool ReadIntegerWithExpectedSize(uint8** pos,
89 uint8* end, 91 uint8* end,
90 size_t expected_size, 92 size_t expected_size,
91 std::vector<uint8>* out); 93 std::vector<uint8>* out);
92 94
93 // Reads an ASN.1 integer from |pos|, and stores the result into |out| with 95 // Reads an ASN.1 integer from |pos|, and stores the result into |out| with
94 // |big_endian| byte-significance. 96 // |big_endian| byte-significance.
95 bool ReadIntegerImpl(uint8** pos, 97 bool ReadIntegerImpl(uint8** pos,
96 uint8* end, 98 uint8* end,
97 std::vector<uint8>* out, 99 std::vector<uint8>* out,
98 bool big_endian); 100 bool big_endian);
99 101
100 // Prepends the integer stored in |val|, starting a index |start|, for 102 // Prepends the integer stored in |val|, starting a index |start|, for
101 // |num_bytes| bytes onto |data|. 103 // |num_bytes| bytes onto |data|.
102 void PrependBytes(uint8* val, 104 void PrependBytes(uint8* val,
103 int start, 105 int start,
104 int num_bytes, 106 int num_bytes,
105 std::list<uint8>* data); 107 std::list<uint8>* data);
106 108
107 // Helper to prepend an ASN.1 length field. 109 // Helper to prepend an ASN.1 length field.
108 void PrependLength(size_t size, std::list<uint8>* data); 110 void PrependLength(size_t size, std::list<uint8>* data);
109 111
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 CSSM_KEY key_; 201 CSSM_KEY key_;
200 CSSM_CSP_HANDLE csp_handle_; 202 CSSM_CSP_HANDLE csp_handle_;
201 #endif 203 #endif
202 204
203 DISALLOW_COPY_AND_ASSIGN(RSAPrivateKey); 205 DISALLOW_COPY_AND_ASSIGN(RSAPrivateKey);
204 }; 206 };
205 207
206 } // namespace base 208 } // namespace base
207 209
208 #endif // BASE_CRYPTO_RSA_PRIVATE_KEY_H_ 210 #endif // BASE_CRYPTO_RSA_PRIVATE_KEY_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698