Skip to content

Commit 7874cc9

Browse files
committed
Add Wildcard verification support
1 parent 83d2aac commit 7874cc9

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

demo/app/assets/httpbin.org.cer

1 Byte
Binary file not shown.

src/https.android.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export function enableSSLPinning(options: Https.HttpsSSLPinningOptions) {
4444
peer.host = options.host;
4545
peer.commonName = options.commonName || options.host;
4646
peer.certificate = certificate;
47+
if (options.commonName) {
48+
peer.commonName = options.commonName;
49+
}
4750
if (options.allowInvalidCertificates === true) {
4851
peer.allowInvalidCertificates = true;
4952
}
@@ -128,12 +131,18 @@ function getClient(reload: boolean = false, timeout: number = 10): okhttp3.OkHtt
128131
verify: (hostname: string, session: javax.net.ssl.SSLSession): boolean => {
129132
let pp = session.getPeerPrincipal().getName();
130133
let hv = javax.net.ssl.HttpsURLConnection.getDefaultHostnameVerifier();
131-
return (
132-
hv.verify(peer.host, session) &&
133-
peer.host === hostname &&
134-
peer.host === session.getPeerHost() &&
135-
pp.indexOf(peer.commonName) !== -1
136-
);
134+
if(peer.commonName && peer.commonName[0] === "*") {
135+
return (hv.verify(peer.host, session) &&
136+
hostname.indexOf(peer.host) > -1 &&
137+
hostname.indexOf(session.getPeerHost()) > -1 &&
138+
pp.indexOf(peer.commonName) !== -1);
139+
}
140+
else {
141+
return (hv.verify(peer.host, session) &&
142+
peer.host === hostname &&
143+
peer.host === session.getPeerHost() &&
144+
pp.indexOf(peer.host) !== -1);
145+
}
137146
},
138147
}));
139148
} catch (error) {

0 commit comments

Comments
 (0)