OLD | NEW |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 description("Tests RTCPeerConnection.generateCertificate RSA/ECDSA."); | 8 description("Tests RTCPeerConnection.generateCertificate RSA/ECDSA."); |
9 | 9 |
| 10 // Constants |
| 11 var minuteInMs = 60 * 1000; |
| 12 var dayInMs = 24 * 60 * minuteInMs; |
| 13 |
10 // Signature of the last generateCertificate call. | 14 // Signature of the last generateCertificate call. |
11 var generateCallString = null; | 15 var generateCallString = null; |
12 // Global certificate variables so that the "should..." methods can evaluate the
m. | 16 // Global certificate variables so that the "should..." methods can evaluate the
m. |
13 var certRSA = null; | 17 var certRSA = null; |
14 var certECDSA = null; | 18 var certECDSA = null; |
| 19 var certExpiresNegativeOneDay = null; |
| 20 var certExpiresZero = null; |
| 21 var certExpiresPositiveOneDay = null; |
15 | 22 |
16 // 1: RSA-2048 using public exponent = 65537. | 23 // 1: RSA-2048 using public exponent = 65537. |
17 function generate1RSA() | 24 function generate1RSA() |
18 { | 25 { |
19 generateCallString = 'generateCertificate({ name: "RSASSA-PKCS1-v1_5", mod
ulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" })'
; | 26 generateCallString = 'generateCertificate({ name: "RSASSA-PKCS1-v1_5", mod
ulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" })'
; |
20 webkitRTCPeerConnection.generateCertificate({ name: "RSASSA-PKCS1-v1_5", mod
ulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" }) | 27 webkitRTCPeerConnection.generateCertificate({ name: "RSASSA-PKCS1-v1_5", mod
ulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" }) |
21 .then(generate1RSASuccessful, generate1RSAFailed); | 28 .then(generate1RSASuccessful, generate1RSAFailed); |
22 } | 29 } |
23 function generate1RSASuccessful(certificate) | 30 function generate1RSASuccessful(certificate) |
24 { | 31 { |
25 certRSA = certificate; | 32 certRSA = certificate; |
26 testPassed(generateCallString); | 33 testPassed(generateCallString); |
27 certificateSanityCheck(certificate, 'certRSA'); | 34 certificateSanityCheck('certRSA'); |
28 generate2ECDSA(); | 35 generate2ECDSA(); |
29 } | 36 } |
30 function generate1RSAFailed() | 37 function generate1RSAFailed() |
31 { | 38 { |
32 testFailed(generateCallString); | 39 testFailed(generateCallString); |
33 generate2ECDSA(); | 40 generate2ECDSA(); |
34 } | 41 } |
35 | 42 |
36 // 2: ECDSA using NIST P-256. | 43 // 2: ECDSA using NIST P-256. |
37 function generate2ECDSA() | 44 function generate2ECDSA() |
38 { | 45 { |
39 generateCallString = 'generateCertificate({ name: "ECDSA", namedCurve: "P-
256" })'; | 46 generateCallString = 'generateCertificate({ name: "ECDSA", namedCurve: "P-
256" })'; |
40 webkitRTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-
256" }) | 47 webkitRTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-
256" }) |
41 .then(generate2ECDSASuccessful, generate2ECDSAFailed); | 48 .then(generate2ECDSASuccessful, generate2ECDSAFailed); |
42 } | 49 } |
43 function generate2ECDSASuccessful(certificate) | 50 function generate2ECDSASuccessful(certificate) |
44 { | 51 { |
45 certECDSA = certificate; | 52 certECDSA = certificate; |
46 testPassed(generateCallString); | 53 testPassed(generateCallString); |
47 certificateSanityCheck(certificate, 'certECDSA'); | 54 certificateSanityCheck('certECDSA'); |
48 finishJSTest(); | 55 generate3ExpiresNegativeOneDay(); |
49 } | 56 } |
50 function generate2ECDSAFailed() | 57 function generate2ECDSAFailed() |
51 { | 58 { |
52 testFailed(generateCallString); | 59 testFailed(generateCallString); |
| 60 generate3ExpiresNegativeOneDay(); |
| 61 } |
| 62 |
| 63 // 3-5: Verify that the |expires| attribute works (generate ECDSA because its fa
ster). |
| 64 function generate3ExpiresNegativeOneDay() |
| 65 { |
| 66 generateCallString = 'generateCertificate({ name: "ECDSA", namedCurve: "P-
256", expires:-dayInMs })'; |
| 67 webkitRTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-
256", expires:-dayInMs }) |
| 68 .then(function(certificate) { certExpiresNegativeOneDay = certificate; g
enerate4ExpiresZero(); }, generate4ExpiresZero); |
| 69 } |
| 70 function generate4ExpiresZero() |
| 71 { |
| 72 generateCallString = 'generateCertificate({ name: "ECDSA", namedCurve: "P-
256", expires:0 })'; |
| 73 webkitRTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-
256", expires:0 }) |
| 74 .then(function(certificate) { certExpiresZero = certificate; generate5Ex
piresPositiveOneDay(); }, generate5ExpiresPositiveOneDay); |
| 75 } |
| 76 function generate5ExpiresPositiveOneDay() |
| 77 { |
| 78 generateCallString = 'generateCertificate({ name: "ECDSA", namedCurve: "P-
256", expires:dayInMs })'; // +1 day |
| 79 webkitRTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-
256", expires:dayInMs }) |
| 80 .then(function(certificate) { certExpiresPositiveOneDay = certificate; g
enerate3to5ExpiresResolved(); }, generate3to5ExpiresResolved); |
| 81 } |
| 82 function generate3to5ExpiresResolved() |
| 83 { |
| 84 // A negative |expires| value is not a DOMTimeStamp, it should be ignored an
d |
| 85 // generate a certificate that has not expired. |
| 86 certificateSanityCheck('certExpiresNegativeOneDay'); |
| 87 |
| 88 // Check that the zero expiration certificate was generated but has expired. |
| 89 shouldBeNonNull('certExpiresZero'); |
| 90 shouldBeTrue('new Date().getTime() >= certExpiresZero.expires'); |
| 91 |
| 92 // Check that the +1 day expiration certificate expires in approximately 1 d
ay (+/- 1 minute). |
| 93 shouldBeNonNull('certExpiresPositiveOneDay'); |
| 94 shouldBeTrue('Math.abs(certExpiresPositiveOneDay.expires - (new Date().getTi
me() + dayInMs)) <= minuteInMs'); |
| 95 |
53 finishJSTest(); | 96 finishJSTest(); |
54 } | 97 } |
55 | 98 |
56 // Helper functions. | 99 // Helper functions. |
57 function certificateSanityCheck(cert, certVariableName) | 100 function certificateSanityCheck(certVariableName) |
58 { | 101 { |
59 shouldBeNonNull(certVariableName); | 102 shouldBeNonNull(certVariableName); |
60 shouldBeTrue('new Date().getTime() < ' + certVariableName + '.expires'); | 103 shouldBeTrue('new Date().getTime() < ' + certVariableName + '.expires'); |
61 } | 104 } |
62 | 105 |
63 // Run each generate test sequentially. The ith generate method will make sure | 106 // Run each generate test sequentially. The ith generate method will make sure |
64 // the (i+1)st generate method is executed when its promise's callbacks are | 107 // the (i+1)st generate method is executed when its promise's callbacks are |
65 // invoked. generate2ECDSA's callback methods mark the end of the async tests. | 108 // invoked. generate2ECDSA's callback methods mark the end of the async tests. |
66 generate1RSA(); | 109 generate1RSA(); |
67 | 110 |
68 window.jsTestIsAsync = true; | 111 window.jsTestIsAsync = true; |
69 window.successfullyParsed = true; | 112 window.successfullyParsed = true; |
70 </script> | 113 </script> |
71 </body> | 114 </body> |
72 </html> | 115 </html> |
OLD | NEW |