summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-01 21:14:33 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-01 21:14:33 +0000
commit395b48dd6f89f1076ffa4480757816ea7587a969 (patch)
tree64b37478fd2404ba11553343ae083be7e9d90a19 /net/base
parent10c24a3b4057dcfb16248a0f0e568ba3a24f4d0b (diff)
downloadchromium_src-395b48dd6f89f1076ffa4480757816ea7587a969.zip
chromium_src-395b48dd6f89f1076ffa4480757816ea7587a969.tar.gz
chromium_src-395b48dd6f89f1076ffa4480757816ea7587a969.tar.bz2
Add a new ExtractSubjectPublicKeyFromSPKI method to asn1_utils.
Review URL: https://chromiumcodereview.appspot.com/10821111 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149492 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/asn1_util.cc30
-rw-r--r--net/base/asn1_util.h7
2 files changed, 36 insertions, 1 deletions
diff --git a/net/base/asn1_util.cc b/net/base/asn1_util.cc
index a1e8637..2f606b6 100644
--- a/net/base/asn1_util.cc
+++ b/net/base/asn1_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -157,6 +157,34 @@ bool ExtractSPKIFromDERCert(base::StringPiece cert,
return true;
}
+bool ExtractSubjectPublicKeyFromSPKI(base::StringPiece spki,
+ base::StringPiece* spk_out) {
+ // From RFC 5280, Section 4.1
+ // SubjectPublicKeyInfo ::= SEQUENCE {
+ // algorithm AlgorithmIdentifier,
+ // subjectPublicKey BIT STRING }
+ //
+ // AlgorithmIdentifier ::= SEQUENCE {
+ // algorithm OBJECT IDENTIFIER,
+ // parameters ANY DEFINED BY algorithm OPTIONAL }
+
+ // Step into SubjectPublicKeyInfo sequence.
+ base::StringPiece spki_contents;
+ if (!asn1::GetElement(&spki, asn1::kSEQUENCE, &spki_contents))
+ return false;
+
+ // Step over algorithm field (a SEQUENCE).
+ base::StringPiece algorithm;
+ if (!asn1::GetElement(&spki_contents, asn1::kSEQUENCE, &algorithm))
+ return false;
+
+ // Extract the subjectPublicKey field.
+ if (!asn1::GetElement(&spki_contents, asn1::kBITSTRING, spk_out))
+ return false;
+ return true;
+}
+
+
bool ExtractCRLURLsFromDERCert(base::StringPiece cert,
std::vector<base::StringPiece>* urls_out) {
urls_out->clear();
diff --git a/net/base/asn1_util.h b/net/base/asn1_util.h
index eb2d473..7c584c4 100644
--- a/net/base/asn1_util.h
+++ b/net/base/asn1_util.h
@@ -63,6 +63,13 @@ bool GetElement(base::StringPiece* in,
NET_EXPORT_PRIVATE bool ExtractSPKIFromDERCert(base::StringPiece cert,
base::StringPiece* spki_out);
+// ExtractSubjectPublicKeyFromSPKI parses the DER encoded SubjectPublicKeyInfo
+// in |spki| and extracts the bytes of the SubjectPublicKey. On successful
+// return, |spk_out| is set to contain the public key, pointing into |spki|.
+NET_EXPORT_PRIVATE bool ExtractSubjectPublicKeyFromSPKI(
+ base::StringPiece spki,
+ base::StringPiece* spk_out);
+
// ExtractCRLURLsFromDERCert parses the DER encoded certificate in |cert| and
// extracts the URL of each CRL. On successful return, the elements of
// |urls_out| point into |cert|.