Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
OPCUAClient.prototype._getApplicationUri = function () {
// get applicationURI from certificate
const exploreCertificate = require("node-opcua-crypto").exploreCertificate;
const certificate = this.getCertificate();
let applicationUri;
if (certificate) {
const e = exploreCertificate(certificate);
if (!e.tbsCertificate.extensions || !e.tbsCertificate.extensions.subjectAltName) {
console.log(chalk.red(" Warning: client certificate is invalid : subjectAltName is missing"));
applicationUri = makeApplicationUrn(hostname, this.applicationName);
} else {
applicationUri = e.tbsCertificate.extensions.subjectAltName.uniformResourceIdentifier[0];
}
} else {
applicationUri = makeApplicationUrn(hostname, this.applicationName);
}
return applicationUri;
};
function validate_applicationUri(applicationUri, clientCertificate) {
// if session is insecure there is no need to check certificate information
if (channel.securityMode === MessageSecurityMode.NONE) {
return true; // assume correct
}
if (!clientCertificate || clientCertificate.length === 0) {
return true;// can't check
}
const e = exploreCertificate(clientCertificate);
const applicationUriFromCert = e.tbsCertificate.extensions.subjectAltName.uniformResourceIdentifier[0];
return applicationUriFromCert === applicationUri;
}
function getUserName(userIdentityToken: UserIdentityToken): string {
if (userIdentityToken instanceof AnonymousIdentityToken) {
return "anonymous";
}
if (userIdentityToken instanceof X509IdentityToken) {
const certInfo: CertificateInternals = exploreCertificate(userIdentityToken.certificateData);
const userName = certInfo.tbsCertificate.subject.commonName || "";
if (typeof userName !== "string") {
throw new Error("Invalid username");
}
return userName;
}
if (userIdentityToken instanceof UserNameIdentityToken) {
if (userIdentityToken.policyId === "anonymous") {
return "anonymous";
}
assert(userIdentityToken.hasOwnProperty("userName"));
return userIdentityToken.userName!;
}
throw new Error("Invalid user identity token");
}