Skip to content

Commit b2c36c5

Browse files
committed
clean-up & certificateVerify handles ECDHE_RSA key exchange algorithm
1 parent cdb88e2 commit b2c36c5

File tree

8 files changed

+97
-112
lines changed

8 files changed

+97
-112
lines changed

modules/crypt/etc/ber.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ export default class BER {
4646
this.#a = buffer;
4747
else
4848
this.#a = new Uint8Array(new ArrayBuffer(0, {maxByteLength: 0x10000000}));
49-
};
49+
}
5050
getTag() {
5151
return this.#a[this.#i++];
52-
};
52+
}
5353
getLength() {
5454
let length = this.#a[this.#i++];
5555
if (length < 128)
@@ -64,19 +64,19 @@ export default class BER {
6464
result = (result << 8) | this.#a[this.#i++];
6565

6666
return result;
67-
};
67+
}
6868
peek() {
6969
return this.#a[this.#i];
70-
};
70+
}
7171
skip(length) {
7272
this.#i += length;
73-
};
73+
}
7474
next() {
7575
const i = this.#i;
7676
this.getTag();
7777
this.skip(this.getLength());
7878
return this.#a.subarray(i, this.#i)
79-
};
79+
}
8080
getInteger() {
8181
if (this.getTag() !== 2)
8282
throw new Error("BER: not an integer");
@@ -92,7 +92,7 @@ export default class BER {
9292
this.skip(length)
9393
return BigInt.fromArrayBuffer(this.#a.buffer.slice(offset, offset + length));
9494
}
95-
};
95+
}
9696
getBitString() {
9797
let result;
9898
if (this.getTag() != 3)
@@ -102,19 +102,19 @@ export default class BER {
102102
if (pad) {
103103
result = new Uint8Array(length - 1);
104104
for (let i = 0; i < length - 1; i++)
105-
bs[i] = this.#a[this.#i++] >>> pad;
105+
result[i] = this.#a[this.#i++] >>> pad;
106106
}
107107
else {
108108
result = this.#a.subarray(this.#i, this.#i + length - 1);
109109
this.#i += length;
110110
}
111111
return result;
112-
};
112+
}
113113
getOctetString() {
114114
if (this.getTag() != 0x04)
115115
throw new Error("BER: not a octet string");
116116
return this.getChunk(this.getLength());
117-
};
117+
}
118118
getObjectIdentifier() {
119119
if (this.getTag() !== 0x06)
120120
throw new Error("BER: not an object identifier");
@@ -131,39 +131,39 @@ export default class BER {
131131
oid.push((v << 7) | i);
132132
}
133133
return Uint32Array.from(oid);
134-
};
134+
}
135135
getSequence() {
136136
if (this.getTag() != 0x30)
137137
throw new Error("BER: not a sequence");
138138
const length = this.getLength();
139139
const result = this.#a.subarray(this.#i, + this.#i + length);
140140
this.#i += length;
141141
return result;
142-
};
142+
}
143143
getChunk(n) {
144144
const result = new Uint8Array(this.#a.buffer, this.#a.byteOffset + this.#i, n);
145145
this.skip(n);
146146
return result;
147-
};
147+
}
148148
getBuffer() {
149149
return this.#a.slice(0, this.#i).buffer;
150-
};
150+
}
151151

152152
morebuf(n) {
153153
if (n < 128) n = 128;
154154
this.#a.buffer.resize(this.#a.length + n);
155-
};
155+
}
156156
getc() {
157157
return this.#a[this.#i++];
158-
};
158+
}
159159
putc(c) {
160160
if (this.#i >= this.#a.length)
161161
this.morebuf(1);
162162
this.#a[this.#i++] = c;
163-
};
163+
}
164164
putTag(tag) {
165165
this.putc(tag);
166-
};
166+
}
167167
putLength(len) {
168168
if (len < 128)
169169
this.putc(len);
@@ -176,13 +176,13 @@ export default class BER {
176176
while (--lenlen >= 0)
177177
this.putc(len >>> (lenlen << 3));
178178
}
179-
};
179+
}
180180
putChunk(c) {
181181
if (this.#i + c.byteLength > this.#a.length)
182182
this.morebuf(c.byteLength);
183183
this.#a.set(new Uint8Array(c), this.#i);
184184
this.#i += c.byteLength;
185-
};
185+
}
186186
get i() {
187187
return this.#i;
188188
}
@@ -191,7 +191,7 @@ export default class BER {
191191
if (n.length < 2)
192192
return "0" + n;
193193
return n;
194-
};
194+
}
195195
static encode(arr) {
196196
const b = new BER;
197197
const tag = arr[0];
@@ -334,7 +334,7 @@ export default class BER {
334334
}
335335
b.#a.buffer.resize(b.#i);
336336
return b.#a.buffer;
337-
};
337+
}
338338
static decode(a) {
339339
return this._decode(new BER(a));
340340
}
@@ -356,7 +356,7 @@ export default class BER {
356356
res = [res];
357357
res.unshift(tag);
358358
return res;
359-
};
359+
}
360360
static decodeTag(tag, b, len) {
361361
let res;
362362
if ((tag >> 6) == 2) { // context specific class
@@ -424,7 +424,6 @@ export default class BER {
424424
break;
425425
case 0x09: // real -- not supported
426426
throw new Error("BER: unsupported");
427-
break;
428427
case 0x07: // object descriptor
429428
case 0x0c: // UTF8 string
430429
case 0x12: // numeric string
@@ -470,7 +469,5 @@ export default class BER {
470469
break;
471470
}
472471
return res;
473-
};
474-
};
475-
476-
Object.freeze(BER.prototype);
472+
}
473+
}

modules/crypt/etc/ecdsa.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,17 @@
3838
import RNG from "rng";
3939
import PKCS1 from "pkcs1";
4040
import Mont from "mont";
41-
import EC from "ec";
42-
import Curve from "curve";
4341
import BER from "ber";
4442

4543
export default class ECDSA {
46-
constructor(key, curve, priv) {
44+
constructor(key, curve /* , priv */) {
4745
this.u = key;
4846
this.G = curve.G;
4947
this.orderSize = curve.orderSize;
5048
this.n = new Mont({m: curve.n});
5149
this.ec = curve.ec;
5250
this.k = curve.k; // just for a debugging purpose
53-
};
51+
}
5452
_sign(H) {
5553
// (r, s) = (k*G, (e + du*r) / k)
5654
var ec = this.ec;
@@ -67,7 +65,7 @@ export default class ECDSA {
6765
var s = n.mul(n.add(e, n.mul(du, r)), n.mulinv(k));
6866
} while (s == 0);
6967
return {r, s};
70-
};
68+
}
7169
sign(H, asn1) {
7270
const sig = this._sign(H);
7371
if (asn1)
@@ -76,7 +74,7 @@ export default class ECDSA {
7674
const os = new ArrayBuffer();
7775
const l = this.orderSize;
7876
return os.concat(PKCS1.I2OSP(sig.r, l), PKCS1.I2OSP(sig.s, l));
79-
};
77+
}
8078
_verify(H, r, s) {
8179
// u1 = e / s
8280
// u2 = r / s
@@ -93,7 +91,7 @@ export default class ECDSA {
9391
// var R = ec.add(ec.mul(G, u1), ec.mul(Qu, u2));
9492
var R = ec.mul2(G, u1, Qu, u2);
9593
return R.X === r;
96-
};
94+
}
9795
verify(H, sig, asn1) {
9896
var r, s;
9997
if (asn1) {
@@ -108,11 +106,11 @@ export default class ECDSA {
108106
s = PKCS1.OS2IP(sig.slice(l, l*2));
109107
}
110108
return this._verify(H, r, s);
111-
};
109+
}
112110
static randint(max) {
113111
var i = BigInt.fromArrayBuffer(RNG.get(BigInt.bitLength(max) >>> 3));
114112
while (i >= max)
115113
i >>>= 1;
116114
return i;
117-
};
118-
};
115+
}
116+
}

modules/crypt/ssl/ssl_cert.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ class CertificateManager {
5656
this.#verify = options.verify ?? true;
5757
if (options.certificate)
5858
this.register(options.certificate);
59-
if (options.clientCertificates)
60-
this.#clientCertificates = options.clientCertificates;
61-
if (options.clientKey)
62-
this.#clientKey = options.clientKey;
59+
this.#clientCertificates = options.clientCertificates;
60+
this.#clientKey = options.clientKey;
6361
}
6462
getCerts() {
6563
// return the self certs

modules/crypt/ssl/ssl_ciphersuites.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2021 Moddable Tech, Inc.
2+
* Copyright (c) 2016-2022 Moddable Tech, Inc.
33
*
44
* This file is part of the Moddable SDK Runtime.
55
*
@@ -36,9 +36,7 @@
3636
*/
3737

3838
import config from "mc/config";
39-
import {AES, CBC, DES, DHE_RSA, ECDHE_RSA, GCM, MD5, NONE, NULL, RSA, SHA1, SHA256, SHA384, TDES} from "ssl/constants";
40-
41-
39+
import {AES, CBC, DHE_RSA, ECDHE_RSA, GCM, RSA, SHA1, SHA256 /* , SHA384, TDES */} from "ssl/constants";
4240

4341
const supportedCipherSuites = [
4442
{

0 commit comments

Comments
 (0)