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

Side by Side Diff: net/spdy/spdy_credential_builder.cc

Issue 10807088: Implement TLS Channel ID support for SPDY CREDENTIAL frames (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Factor out MockClientSocket::kTlsUnique. Created 8 years, 4 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/spdy/spdy_credential_builder.h"
6
7 #include "base/logging.h"
8 #include "base/string_piece.h"
9 #include "crypto/ec_private_key.h"
10 #include "crypto/ec_signature_creator.h"
11 #include "crypto/signature_creator.h"
12 #include "net/base/asn1_util.h"
13 #include "net/base/server_bound_cert_service.h"
14 #include "net/base/net_errors.h"
15 #include "net/socket/ssl_client_socket.h"
16 #include "net/spdy/spdy_framer.h"
17
18 namespace net {
19
20 // static
21 int SpdyCredentialBuilder::Build(std::string tls_unique,
22 SSLClientCertType type,
23 const std::string& key,
24 const std::string& cert,
25 size_t slot,
26 SpdyCredential* credential) {
27 DCHECK(type == CLIENT_CERT_ECDSA_SIGN);
28 if (type != CLIENT_CERT_ECDSA_SIGN)
29 return ERR_BAD_SSL_CLIENT_AUTH_CERT;
30
31 std::string secret = SpdyCredentialBuilder::GetCredentialSecret(tls_unique);
32
33 // Extract the SubjectPublicKeyInfo from the certificate.
34 base::StringPiece spki;
35 if(!asn1::ExtractSPKIFromDERCert(cert, &spki))
36 return ERR_BAD_SSL_CLIENT_AUTH_CERT;
37
38 // Next, extract the SubjectPublicKey data, which will actually
39 // be stored in the cert field of the credential frame.
40 base::StringPiece spk;
jar (doing other things) 2012/08/02 02:23:04 nit: abbreviations are discouraged.. WTC said tha
Ryan Hamilton 2012/08/02 15:53:49 Done
41 if (!asn1::ExtractSubjectPublicKeyFromSPKI(spki, &spk))
42 return ERR_BAD_SSL_CLIENT_AUTH_CERT;
43 // Drop one byte of padding bits count from the BIT STRING
44 // (this will always be zero). Drop one byte of X9.62 format specification
45 // (this will always be 4 to indicated an uncompressed point)
46 DCHECK_EQ(0, (int)spk[0]);
ramant (doing other things) 2012/08/02 00:03:05 overly nit: period at the end of comments (here an
Ryan Hamilton 2012/08/02 15:53:49 (weird, your comment is off by a line again. Is t
47 DCHECK_EQ(4, (int)spk[1]);
jar (doing other things) 2012/08/02 02:23:04 Consider static_cast<int> rather than C style.
Ryan Hamilton 2012/08/02 15:53:49 Done.
48 spk = spk.substr(2, spk.length());
49
ramant (doing other things) 2012/08/02 00:03:05 nit: should we DCHECK_GE(spk.length(), 2)?
Ryan Hamilton 2012/08/02 15:53:49 Done.
50 // Convert the strings into a vector<unit8>
51 std::vector<uint8> spki_data(spki.data(),
52 spki.data() + spki.size());
jar (doing other things) 2012/08/02 02:23:04 nit: no need to wrap.
Ryan Hamilton 2012/08/02 15:53:49 Heh, the longer names complicated this :> I ended
53 std::vector<uint8> key_data(key.data(),
54 key.data() + key.length());
55 std::vector<uint8> proof_data;
56 scoped_ptr<crypto::ECPrivateKey> private_key(
57 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
58 ServerBoundCertService::kEPKIPassword, key_data, spki_data));
59 scoped_ptr<crypto::ECSignatureCreator> creator(
60 crypto::ECSignatureCreator::Create(private_key.get()));
61 creator->Sign(reinterpret_cast<const unsigned char *>(secret.data()),
62 secret.length(), &proof_data);
63
64 credential->slot = slot;
65 credential->certs.push_back(spk.as_string());
66 credential->proof.assign(proof_data.begin(), proof_data.end());
ramant (doing other things) 2012/08/02 00:03:05 nit: it was confusing for me to store SubjectPubli
Ryan Hamilton 2012/08/02 15:53:49 I hear you. Until we change the spec, I'd prefer
67 return OK;
68 }
69
70 // static
71 std::string SpdyCredentialBuilder::GetCredentialSecret(std::string tls_unique) {
72 const char prefix[] = "SPDY CREDENTIAL ChannelID\0client -> server";
73 std::string secret(prefix, arraysize(prefix));
74 secret.append(tls_unique);
75
76 return secret;
77 }
78
79 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698