Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / net / cert / x509_certificate_ios.cc
index f59cb65..bc76d08 100644 (file)
@@ -186,6 +186,22 @@ SHA1HashValue X509Certificate::CalculateFingerprint(
 }
 
 // static
+SHA256HashValue X509Certificate::CalculateFingerprint256(OSCertHandle cert) {
+  SHA256HashValue sha256;
+  memset(sha256.data, 0, sizeof(sha256.data));
+
+  ScopedCFTypeRef<CFDataRef> cert_data(SecCertificateCopyData(cert));
+  if (!cert_data)
+    return sha256;
+  DCHECK(CFDataGetBytePtr(cert_data));
+  DCHECK_NE(0, CFDataGetLength(cert_data));
+  CC_SHA256(
+      CFDataGetBytePtr(cert_data), CFDataGetLength(cert_data), sha256.data);
+
+  return sha256;
+}
+
+// static
 SHA1HashValue X509Certificate::CalculateCAFingerprint(
     const OSCertHandles& intermediates) {
   SHA1HashValue sha1;
@@ -234,4 +250,15 @@ void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle,
   x509_util::GetPublicKeyInfo(nss_cert.cert_handle(), size_bits, type);
 }
 
+// static
+bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) {
+  x509_util_ios::NSSCertificate nss_cert(cert_handle);
+  crypto::ScopedSECKEYPublicKey public_key(
+      CERT_ExtractPublicKey(nss_cert.cert_handle()));
+  if (!public_key.get())
+    return false;
+  return SECSuccess == CERT_VerifySignedDataWithPublicKey(
+      &nss_cert.cert_handle()->signatureWrap, public_key.get(), NULL);
+}
+
 }  // namespace net