@@ -57,6 +57,7 @@ INCLUDE('Root-CAs');
5757INCLUDE ( 'sha256' ) ;
5858INCLUDE ( 'X509ChainWhitelist' ) ;
5959INCLUDE ( 'NSS' ) ;
60+ INCLUDE ( 'md5' ) ;
6061
6162function SSLObservatory ( ) {
6263 this . prefs = CC [ "@mozilla.org/preferences-service;1" ]
@@ -285,9 +286,31 @@ SSLObservatory.prototype = {
285286 },
286287 */
287288
289+ // Calculate the MD5 fingerprint for a cert. This is the fingerprint of the
290+ // DER-encoded form, same as the result of
291+ // openssl x509 -md5 -fingerprint -noout
292+ // We use this because the SSL Observatory depends in many places on a special
293+ // fingerprint which is the concatenation of MD5+SHA1, and the MD5 fingerprint
294+ // is no longer available on the cert object.
295+ // Implementation cribbed from
296+ // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsICryptoHash
297+ md5Fingerprint : function ( cert ) {
298+ var len = new Object ( ) ;
299+ var derData = cert . getRawDER ( len ) ;
300+ var ch = CC [ "@mozilla.org/security/hash;1" ] . createInstance ( CI . nsICryptoHash ) ;
301+ ch . init ( ch . MD5 ) ;
302+ ch . update ( derData , derData . length ) ;
303+ var h = ch . finish ( false ) ;
304+
305+ function toHexString ( charCode ) {
306+ return ( "0" + charCode . toString ( 16 ) ) . slice ( - 2 ) ;
307+ }
308+ return [ toHexString ( h . charCodeAt ( i ) ) for ( i in h ) ] . join ( "" ) . toUpperCase ( ) ;
309+ } ,
310+
288311 ourFingerprint : function ( cert ) {
289312 // Calculate our custom fingerprint from an nsIX509Cert
290- return cert . sha1Fingerprint . replace ( ":" , "" , "g" ) ;
313+ return ( this . md5Fingerprint ( cert ) + cert . sha1Fingerprint ) . replace ( ":" , "" , "g" ) ;
291314 } ,
292315
293316 observe : function ( subject , topic , data ) {
0 commit comments