Skip to content

Commit

Permalink
Bug 1385146 - Experimental API, r=ekr
Browse files Browse the repository at this point in the history
--HG--
extra : source : 2ee5a53ee2412a8adce32ed96bd7903a34e14905
extra : amend_source : 7389c6910c42239d9b16c71341f33e9d6935148b
extra : intermediate-source : bb10e9d5ec116ca72e7131811b772aae37996e23
  • Loading branch information
martinthomson committed Jun 30, 2017
1 parent a853912 commit c960d70
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions gtests/ssl_gtest/manifest.mn
Expand Up @@ -30,6 +30,7 @@ CPPSRCS = \
ssl_gtest.cc \
ssl_hrr_unittest.cc \
ssl_loopback_unittest.cc \
ssl_misc_unittest.cc \
ssl_record_unittest.cc \
ssl_resumption_unittest.cc \
ssl_skip_unittest.cc \
Expand Down
1 change: 1 addition & 0 deletions gtests/ssl_gtest/ssl_0rtt_unittest.cc
Expand Up @@ -7,6 +7,7 @@
#include "secerr.h"
#include "ssl.h"
#include "sslerr.h"
#include "sslexp.h"
#include "sslproto.h"

extern "C" {
Expand Down
1 change: 1 addition & 0 deletions gtests/ssl_gtest/ssl_gtest.gyp
Expand Up @@ -31,6 +31,7 @@
'ssl_gtest.cc',
'ssl_hrr_unittest.cc',
'ssl_loopback_unittest.cc',
'ssl_misc_unittest.cc',
'ssl_record_unittest.cc',
'ssl_resumption_unittest.cc',
'ssl_skip_unittest.cc',
Expand Down
20 changes: 20 additions & 0 deletions gtests/ssl_gtest/ssl_misc_unittest.cc
@@ -0,0 +1,20 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "sslexp.h"

#include "gtest_utils.h"

namespace nss_test {

class MiscTest : public ::testing::Test {};

TEST_F(MiscTest, NonExistentExperimentalAPI) {
EXPECT_EQ(nullptr, SSL_GetExperimentalAPI("blah"));
EXPECT_EQ(SSL_ERROR_UNSUPPORTED_EXPERIMENTAL_API, PORT_GetError());
}

} // namespace nss_test
1 change: 1 addition & 0 deletions gtests/ssl_gtest/tls_connect.cc
Expand Up @@ -5,6 +5,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "tls_connect.h"
#include "sslexp.h"
extern "C" {
#include "libssl_internals.h"
}
Expand Down
9 changes: 9 additions & 0 deletions lib/ssl/SSLerrs.h
Expand Up @@ -511,3 +511,12 @@ ER3(SSL_ERROR_DOWNGRADE_WITH_EARLY_DATA, (SSL_ERROR_BASE + 160),

ER3(SSL_ERROR_TOO_MUCH_EARLY_DATA, (SSL_ERROR_BASE + 161),
"SSL received more early data than permitted.")

ER3(SSL_ERROR_RX_UNEXPECTED_END_OF_EARLY_DATA, (SSL_ERROR_BASE + 162),
"SSL received an unexpected End of Early Data message.")

ER3(SSL_ERROR_RX_MALFORMED_END_OF_EARLY_DATA, (SSL_ERROR_BASE + 163),
"SSL received a malformed End of Early Data message.")

ER3(SSL_ERROR_UNSUPPORTED_EXPERIMENTAL_API, (SSL_ERROR_BASE + 164),
"An experimental API was called, but not supported.")
1 change: 1 addition & 0 deletions lib/ssl/exports.gyp
Expand Up @@ -15,6 +15,7 @@
'preenc.h',
'ssl.h',
'sslerr.h',
'sslexp.h',
'sslproto.h',
'sslt.h'
],
Expand Down
1 change: 1 addition & 0 deletions lib/ssl/manifest.mn
Expand Up @@ -10,6 +10,7 @@ EXPORTS = \
ssl.h \
sslt.h \
sslerr.h \
sslexp.h \
sslproto.h \
preenc.h \
$(NULL)
Expand Down
6 changes: 6 additions & 0 deletions lib/ssl/ssl.def
Expand Up @@ -234,3 +234,9 @@ SSL_AlertSentCallback;
;+ local:
;+*;
;+};
;+NSS_3.33 { # NSS 3.33 release
;+ global:
SSL_GetExperimentalAPI;
;+ local:
;+*;
;+};
7 changes: 7 additions & 0 deletions lib/ssl/ssl.h
Expand Up @@ -1374,6 +1374,13 @@ extern const char *NSSSSL_GetVersion(void);
*/
SSL_IMPORT SECStatus SSL_AuthCertificateComplete(PRFileDesc *fd,
PRErrorCode error);

/*
* This is used to access experimental APIs. Don't call this directly. This is
* used to enable the experimental APIs that are defined in "sslexp.h".
*/
SSL_IMPORT void *SSL_GetExperimentalAPI(const char *name);

SEC_END_PROTOS

#endif /* __ssl_h_ */
5 changes: 5 additions & 0 deletions lib/ssl/sslerr.h
Expand Up @@ -246,6 +246,11 @@ typedef enum {
SSL_ERROR_MISSING_PSK_KEY_EXCHANGE_MODES = (SSL_ERROR_BASE + 159),
SSL_ERROR_DOWNGRADE_WITH_EARLY_DATA = (SSL_ERROR_BASE + 160),
SSL_ERROR_TOO_MUCH_EARLY_DATA = (SSL_ERROR_BASE + 161),
SSL_ERROR_RX_UNEXPECTED_END_OF_EARLY_DATA = (SSL_ERROR_BASE + 162),
SSL_ERROR_RX_MALFORMED_END_OF_EARLY_DATA = (SSL_ERROR_BASE + 163),

SSL_ERROR_UNSUPPORTED_EXPERIMENTAL_API = (SSL_ERROR_BASE + 164),

SSL_ERROR_END_OF_LIST /* let the c compiler determine the value of this. */
} SSLErrorCodes;
#endif /* NO_SECURITY_ERROR_ENUM */
Expand Down
27 changes: 27 additions & 0 deletions lib/ssl/sslexp.h
@@ -0,0 +1,27 @@
/*
* This file contains prototypes for experimental SSL functions.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __sslexp_h_
#define __sslexp_h_

#include "ssl.h"
#include "sslerr.h"

SEC_BEGIN_PROTOS

/* The functions in this header file are not guaranteed to remain available in
* future NSS versions. Code that uses these functions needs to safeguard
* against the function not being available. */

#define SSL_EXPERIMENTAL_API(name, arglist, args) \
(SSL_GetExperimentalAPI(name) \
? ((SECStatus(*) arglist)SSL_GetExperimentalAPI(name))args \
: SECFailure)

SEC_END_PROTOS

#endif /* __sslexp_h_ */
44 changes: 44 additions & 0 deletions lib/ssl/sslsock.c
Expand Up @@ -11,6 +11,7 @@
#include "cert.h"
#include "keyhi.h"
#include "ssl.h"
#include "sslexp.h"
#include "sslimpl.h"
#include "sslproto.h"
#include "nspr.h"
Expand Down Expand Up @@ -3840,3 +3841,46 @@ SSL_CanBypass(CERTCertificate *cert, SECKEYPrivateKey *srvPrivkey,
*pcanbypass = PR_FALSE;
return SECSuccess;
}

/* Functions that are truly experimental use EXP, functions that are no longer
* experimental use PUB.
*
* When initially defining a new API, add that API here using the EXP() macro
* and name the function with a SSLExp_ prefix. Define the experimental API as
* a macro in sslexp.h using the SSL_EXPERIMENTAL_API() macro defined there.
*
* Once an API is stable and proven, move the macro definition in sslexp.h to a
* proper function declaration in ssl.h. Keeping the function in this list
* ensures that code built against the release that contained the experimental
* API will continue to work; use PUB() to reference the public function.
*/
#define EXP(n) \
{ \
"SSL_" #n, SSLExp_##n \
}
#define PUB(n) \
{ \
"SSL_" #n, SSL_##n \
}
struct {
const char *const name;
void *function;
} ssl_experimental_functions[] = {
#ifndef SSL_DISABLE_EXPERIMENTAL_API
#endif
};
#undef EXP
#undef PUB

void *
SSL_GetExperimentalAPI(const char *name)
{
unsigned int i;
for (i = 0; i < PR_ARRAY_SIZE(ssl_experimental_functions); ++i) {
if (strcmp(name, ssl_experimental_functions[i].name) == 0) {
return ssl_experimental_functions[i].function;
}
}
PORT_SetError(SSL_ERROR_UNSUPPORTED_EXPERIMENTAL_API);
return NULL;
}

0 comments on commit c960d70

Please sign in to comment.