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

Side by Side Diff: content/renderer/webcrypto/webcrypto_impl_unittest.cc

Issue 104923004: [webcrypto] Implicitly set public keys to extractable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/webcrypto/webcrypto_impl_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 "content/renderer/webcrypto/webcrypto_impl.h" 5 #include "content/renderer/webcrypto/webcrypto_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 bool extractable = false; 1129 bool extractable = false;
1130 const blink::WebCryptoKeyUsageMask usage_mask = 0; 1130 const blink::WebCryptoKeyUsageMask usage_mask = 0;
1131 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); 1131 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
1132 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); 1132 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
1133 EXPECT_TRUE(GenerateKeyPairInternal( 1133 EXPECT_TRUE(GenerateKeyPairInternal(
1134 algorithm, extractable, usage_mask, &public_key, &private_key)); 1134 algorithm, extractable, usage_mask, &public_key, &private_key));
1135 EXPECT_FALSE(public_key.isNull()); 1135 EXPECT_FALSE(public_key.isNull());
1136 EXPECT_FALSE(private_key.isNull()); 1136 EXPECT_FALSE(private_key.isNull());
1137 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); 1137 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type());
1138 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); 1138 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type());
1139 EXPECT_EQ(extractable, public_key.extractable()); 1139 EXPECT_EQ(true, public_key.extractable());
1140 EXPECT_EQ(extractable, private_key.extractable()); 1140 EXPECT_EQ(extractable, private_key.extractable());
1141 EXPECT_EQ(usage_mask, public_key.usages()); 1141 EXPECT_EQ(usage_mask, public_key.usages());
1142 EXPECT_EQ(usage_mask, private_key.usages()); 1142 EXPECT_EQ(usage_mask, private_key.usages());
1143 1143
1144 // Fail with bad modulus. 1144 // Fail with bad modulus.
1145 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( 1145 algorithm = webcrypto::CreateRsaKeyGenAlgorithm(
1146 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent); 1146 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent);
1147 EXPECT_FALSE(GenerateKeyPairInternal( 1147 EXPECT_FALSE(GenerateKeyPairInternal(
1148 algorithm, extractable, usage_mask, &public_key, &private_key)); 1148 algorithm, extractable, usage_mask, &public_key, &private_key));
1149 1149
(...skipping 30 matching lines...) Expand all
1180 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( 1180 algorithm = webcrypto::CreateRsaKeyGenAlgorithm(
1181 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 1181 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
1182 modulus_length, 1182 modulus_length,
1183 exponent_with_leading_zeros); 1183 exponent_with_leading_zeros);
1184 EXPECT_TRUE(GenerateKeyPairInternal( 1184 EXPECT_TRUE(GenerateKeyPairInternal(
1185 algorithm, extractable, usage_mask, &public_key, &private_key)); 1185 algorithm, extractable, usage_mask, &public_key, &private_key));
1186 EXPECT_FALSE(public_key.isNull()); 1186 EXPECT_FALSE(public_key.isNull());
1187 EXPECT_FALSE(private_key.isNull()); 1187 EXPECT_FALSE(private_key.isNull());
1188 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); 1188 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type());
1189 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); 1189 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type());
1190 EXPECT_EQ(extractable, public_key.extractable()); 1190 EXPECT_EQ(true, public_key.extractable());
1191 EXPECT_EQ(extractable, private_key.extractable()); 1191 EXPECT_EQ(extractable, private_key.extractable());
1192 EXPECT_EQ(usage_mask, public_key.usages()); 1192 EXPECT_EQ(usage_mask, public_key.usages());
1193 EXPECT_EQ(usage_mask, private_key.usages()); 1193 EXPECT_EQ(usage_mask, private_key.usages());
1194 1194
1195 // Successful WebCryptoAlgorithmIdRsaOaep key generation. 1195 // Successful WebCryptoAlgorithmIdRsaOaep key generation.
1196 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( 1196 algorithm = webcrypto::CreateRsaKeyGenAlgorithm(
1197 blink::WebCryptoAlgorithmIdRsaOaep, modulus_length, public_exponent); 1197 blink::WebCryptoAlgorithmIdRsaOaep, modulus_length, public_exponent);
1198 EXPECT_TRUE(GenerateKeyPairInternal( 1198 EXPECT_TRUE(GenerateKeyPairInternal(
1199 algorithm, extractable, usage_mask, &public_key, &private_key)); 1199 algorithm, extractable, usage_mask, &public_key, &private_key));
1200 EXPECT_FALSE(public_key.isNull()); 1200 EXPECT_FALSE(public_key.isNull());
1201 EXPECT_FALSE(private_key.isNull()); 1201 EXPECT_FALSE(private_key.isNull());
1202 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); 1202 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type());
1203 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); 1203 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type());
1204 EXPECT_EQ(extractable, public_key.extractable()); 1204 EXPECT_EQ(true, public_key.extractable());
1205 EXPECT_EQ(extractable, private_key.extractable()); 1205 EXPECT_EQ(extractable, private_key.extractable());
1206 EXPECT_EQ(usage_mask, public_key.usages()); 1206 EXPECT_EQ(usage_mask, public_key.usages());
1207 EXPECT_EQ(usage_mask, private_key.usages()); 1207 EXPECT_EQ(usage_mask, private_key.usages());
1208 1208
1209 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation. 1209 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation.
1210 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( 1210 algorithm = webcrypto::CreateRsaKeyGenAlgorithm(
1211 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, 1211 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
1212 modulus_length, 1212 modulus_length,
1213 public_exponent); 1213 public_exponent);
1214 EXPECT_TRUE(GenerateKeyPairInternal( 1214 EXPECT_TRUE(GenerateKeyPairInternal(
1215 algorithm, extractable, usage_mask, &public_key, &private_key)); 1215 algorithm, extractable, usage_mask, &public_key, &private_key));
1216 EXPECT_FALSE(public_key.isNull()); 1216 EXPECT_FALSE(public_key.isNull());
1217 EXPECT_FALSE(private_key.isNull()); 1217 EXPECT_FALSE(private_key.isNull());
1218 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); 1218 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type());
1219 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); 1219 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type());
1220 EXPECT_EQ(extractable, public_key.extractable()); 1220 EXPECT_EQ(true, public_key.extractable());
1221 EXPECT_EQ(extractable, private_key.extractable()); 1221 EXPECT_EQ(extractable, private_key.extractable());
1222 EXPECT_EQ(usage_mask, public_key.usages()); 1222 EXPECT_EQ(usage_mask, public_key.usages());
1223 EXPECT_EQ(usage_mask, private_key.usages()); 1223 EXPECT_EQ(usage_mask, private_key.usages());
1224 1224
1225 // Fail SPKI export of private key. This is an ExportKey test, but do it here 1225 // Fail SPKI export of private key. This is an ExportKey test, but do it here
1226 // since it is expensive to generate an RSA key pair and we already have a 1226 // since it is expensive to generate an RSA key pair and we already have a
1227 // private key here. 1227 // private key here.
1228 blink::WebArrayBuffer output; 1228 blink::WebArrayBuffer output;
1229 EXPECT_FALSE( 1229 EXPECT_FALSE(
1230 ExportKeyInternal(blink::WebCryptoKeyFormatSpki, private_key, &output)); 1230 ExportKeyInternal(blink::WebCryptoKeyFormatSpki, private_key, &output));
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 private_key, 1481 private_key,
1482 reinterpret_cast<const unsigned char*>(encrypted_data.data()), 1482 reinterpret_cast<const unsigned char*>(encrypted_data.data()),
1483 encrypted_data.byteLength(), 1483 encrypted_data.byteLength(),
1484 &decrypted_data)); 1484 &decrypted_data));
1485 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); 1485 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data);
1486 } 1486 }
1487 1487
1488 #endif // #if !defined(USE_OPENSSL) 1488 #endif // #if !defined(USE_OPENSSL)
1489 1489
1490 } // namespace content 1490 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/webcrypto/webcrypto_impl_nss.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698