Skip to content

Commit c6b431c

Browse files
authored
Merge pull request #428 from pabuhler/ci-nss-valgrind
enable valgrind in nss builds
2 parents 6c02d03 + 2037711 commit c6b431c

File tree

5 files changed

+48
-29
lines changed

5 files changed

+48
-29
lines changed

.travis.yml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,44 @@ env:
99
matrix:
1010
include:
1111

12-
# default linux build with gcc
12+
# linux build
1313
- os: linux
1414
env:
15-
- TEST="linux gcc"
15+
- TEST="linux (gcc / valgrind)"
1616
addons:
1717
apt:
1818
sources:
1919
- ubuntu-toolchain-r-test
2020
packages:
21-
- gcc-6
21+
- gcc-6
22+
- valgrind
2223
script:
2324
- CC=gcc-6 EXTRA_CFLAGS=-Werror ./configure
2425
- make
2526
- make runtest
27+
- make runtest-valgrind
2628

27-
# linux build with openssl and gcc
29+
# linux build with openssl
2830
- os: linux
2931
env:
30-
- TEST="linux gcc (openssl)"
32+
- TEST="linux openssl (gcc / valgrind)"
3133
addons:
3234
apt:
3335
sources:
3436
- ubuntu-toolchain-r-test
3537
packages:
3638
- gcc-6
39+
- valgrind
3740
script:
3841
- CC=gcc-6 EXTRA_CFLAGS=-Werror ./configure --enable-openssl
3942
- make
4043
- make runtest
44+
- make runtest-valgrind
4145

4246
# linux build with openssl and clang
4347
- os: linux
4448
env:
45-
- TEST="linux clang (openssl)"
49+
- TEST="linux openssl (clang)"
4650
addons:
4751
apt:
4852
packages:
@@ -55,18 +59,20 @@ matrix:
5559
# linux build with nss
5660
- os: linux
5761
env:
58-
- TEST="linux gcc (nss)"
62+
- TEST="linux nss (gcc / valgrind)"
5963
addons:
6064
apt:
6165
sources:
6266
- ubuntu-toolchain-r-test
6367
packages:
6468
- gcc-6
69+
- valgrind
6570
- libnss3-dev
6671
script:
6772
- CC=gcc-6 EXTRA_CFLAGS=-Werror ./configure --enable-nss
6873
- make
6974
- make runtest
75+
- make runtest-valgrind
7076

7177
# default osx build with xcode (clang)
7278
- os: osx
@@ -101,22 +107,6 @@ matrix:
101107
script:
102108
- CLANG_FORMAT=clang-format-3.9 ./format.sh -d
103109

104-
# valgrind
105-
- os: linux
106-
env:
107-
- TEST="valgrind (openssl)"
108-
addons:
109-
apt:
110-
sources:
111-
- ubuntu-toolchain-r-test
112-
packages:
113-
- gcc-6
114-
- valgrind
115-
script:
116-
- CC=gcc-6 ./configure --enable-openssl
117-
- make
118-
- make runtest-valgrind
119-
120110
# big-endian
121111
- os: linux
122112
sudo: true

crypto/cipher/aes_gcm_nss.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#include "err.h" /* for srtp_debug */
5454
#include "crypto_types.h"
5555
#include "cipher_types.h"
56-
#include <nss.h>
5756
#include <secerr.h>
5857
#include <nspr.h>
5958

@@ -82,6 +81,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_alloc(srtp_cipher_t **c,
8281
int tlen)
8382
{
8483
srtp_aes_gcm_ctx_t *gcm;
84+
NSSInitContext *nss;
8585

8686
debug_print(srtp_mod_aes_gcm, "allocating cipher with key length %d",
8787
key_len);
@@ -99,24 +99,32 @@ static srtp_err_status_t srtp_aes_gcm_nss_alloc(srtp_cipher_t **c,
9999
return (srtp_err_status_bad_param);
100100
}
101101

102-
/* Initialize NSS */
103-
if (!NSS_IsInitialized() && NSS_NoDB_Init(NULL) != SECSuccess) {
102+
/* Initialize NSS equiv of NSS_NoDB_Init(NULL) */
103+
nss = NSS_InitContext("", "", "", "", NULL,
104+
NSS_INIT_READONLY | NSS_INIT_NOCERTDB |
105+
NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN |
106+
NSS_INIT_OPTIMIZESPACE);
107+
if (!nss) {
104108
return (srtp_err_status_cipher_fail);
105109
}
106110

107111
/* allocate memory a cipher of type aes_gcm */
108112
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
109113
if (*c == NULL) {
114+
NSS_ShutdownContext(nss);
110115
return (srtp_err_status_alloc_fail);
111116
}
112117

113118
gcm = (srtp_aes_gcm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_gcm_ctx_t));
114119
if (gcm == NULL) {
120+
NSS_ShutdownContext(nss);
115121
srtp_crypto_free(*c);
116122
*c = NULL;
117123
return (srtp_err_status_alloc_fail);
118124
}
119125

126+
gcm->nss = nss;
127+
120128
/* set pointers */
121129
(*c)->state = gcm;
122130

@@ -161,6 +169,11 @@ static srtp_err_status_t srtp_aes_gcm_nss_dealloc(srtp_cipher_t *c)
161169
PK11_FreeSymKey(ctx->key);
162170
}
163171

172+
if (ctx->nss) {
173+
NSS_ShutdownContext(ctx->nss);
174+
ctx->nss = NULL;
175+
}
176+
164177
/* zeroize the key material */
165178
octet_string_set_to_zero(ctx, sizeof(srtp_aes_gcm_ctx_t));
166179
srtp_crypto_free(ctx);

crypto/cipher/aes_icm_nss.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include "err.h" /* for srtp_debug */
5353
#include "alloc.h"
5454
#include "cipher_types.h"
55-
#include <nss.h>
5655

5756
srtp_debug_module_t srtp_mod_aes_icm = {
5857
0, /* debugging is off by default */
@@ -106,6 +105,7 @@ static srtp_err_status_t srtp_aes_icm_nss_alloc(srtp_cipher_t **c,
106105
int tlen)
107106
{
108107
srtp_aes_icm_ctx_t *icm;
108+
NSSInitContext *nss;
109109

110110
debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d",
111111
key_len);
@@ -119,26 +119,33 @@ static srtp_err_status_t srtp_aes_icm_nss_alloc(srtp_cipher_t **c,
119119
return srtp_err_status_bad_param;
120120
}
121121

122-
/* Initialize NSS */
123-
if (!NSS_IsInitialized() && NSS_NoDB_Init(NULL) != SECSuccess) {
122+
/* Initialize NSS equiv of NSS_NoDB_Init(NULL) */
123+
nss = NSS_InitContext("", "", "", "", NULL,
124+
NSS_INIT_READONLY | NSS_INIT_NOCERTDB |
125+
NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN |
126+
NSS_INIT_OPTIMIZESPACE);
127+
if (!nss) {
124128
return (srtp_err_status_cipher_fail);
125129
}
126130

127131
/* allocate memory a cipher of type aes_icm */
128132
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
129133
if (*c == NULL) {
134+
NSS_ShutdownContext(nss);
130135
return srtp_err_status_alloc_fail;
131136
}
132137

133138
icm = (srtp_aes_icm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_icm_ctx_t));
134139
if (icm == NULL) {
140+
NSS_ShutdownContext(nss);
135141
srtp_crypto_free(*c);
136142
*c = NULL;
137143
return srtp_err_status_alloc_fail;
138144
}
139145

140146
icm->key = NULL;
141147
icm->ctx = NULL;
148+
icm->nss = nss;
142149

143150
/* set pointers */
144151
(*c)->state = icm;
@@ -188,6 +195,11 @@ static srtp_err_status_t srtp_aes_icm_nss_dealloc(srtp_cipher_t *c)
188195
ctx->ctx = NULL;
189196
}
190197

198+
if (ctx->nss) {
199+
NSS_ShutdownContext(ctx->nss);
200+
ctx->nss = NULL;
201+
}
202+
191203
/* zeroize everything */
192204
octet_string_set_to_zero(ctx, sizeof(srtp_aes_icm_ctx_t));
193205
srtp_crypto_free(ctx);

crypto/include/aes_gcm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ typedef struct {
6666

6767
#ifdef NSS
6868

69+
#include <nss.h>
6970
#include <pk11pub.h>
7071

7172
#define MAX_AD_SIZE 2048
@@ -74,6 +75,7 @@ typedef struct {
7475
int key_size;
7576
int tag_size;
7677
srtp_cipher_direction_t dir;
78+
NSSInitContext *nss;
7779
PK11SymKey *key;
7880
uint8_t iv[12];
7981
uint8_t aad[MAX_AD_SIZE];

crypto/include/aes_icm_ext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ typedef struct {
6565

6666
#ifdef NSS
6767

68+
#include <nss.h>
6869
#include <pk11pub.h>
6970

7071
typedef struct {
7172
v128_t counter;
7273
v128_t offset;
7374
int key_size;
7475
uint8_t iv[16];
76+
NSSInitContext *nss;
7577
PK11SymKey *key;
7678
PK11Context *ctx;
7779
} srtp_aes_icm_ctx_t;

0 commit comments

Comments
 (0)