本文整理汇总了TypeScript中node-opcua-crypto.split_der函数的典型用法代码示例。如果您正苦于以下问题:TypeScript split_der函数的具体用法?TypeScript split_der怎么用?TypeScript split_der使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了split_der函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("applyChanges shall replace certificate ", async () => {
// given a PushCertificateManager that has received a new certificate
const resultCSR = await pushManager.createSigningRequest(
"DefaultApplicationGroup",
"",
"O=NodeOPCUA, CN=urn:NodeOPCUA-Server");
resultCSR.certificateSigningRequest!.should.be.instanceOf(Buffer);
const certificateFull = await produceCertificate(resultCSR.certificateSigningRequest!);
const certificateChain = split_der(certificateFull);
const certificate = certificateChain[0];
const issuerCertificates = certificateChain.slice(1);
const result: UpdateCertificateResult = await pushManager.updateCertificate(
"DefaultApplicationGroup",
"",
certificate,
issuerCertificates
);
// and Given
const existingCertificate1 = await getCertificateDER(pushManager.applicationGroup!);
// When I call ApplyChanges
await pushManager.applyChanges();
// Then I should verify that the certificate has changed
const existingCertificateAfterApplyChange = await getCertificateDER(pushManager.applicationGroup!);
existingCertificateAfterApplyChange.toString("hex").
should.not.eql(existingCertificate1.toString("hex"));
});
示例2: getCertificate
public getCertificate(): Certificate {
if (!this.certificate) {
const certChain = this.getCertificateChain();
this.certificate = split_der(certChain)[0] as Certificate;
}
return this.certificate;
}
示例3: getCertificate
function getCertificate(this: OPCUAServerPartial): Certificate {
if (!this.$$certificate) {
const certificateChain = getCertificateChain.call(this);
this.$$certificate = split_der(certificateChain)[0];
}
return this.$$certificate!;
}
示例4: function
getCertificate: function() {
const chain = this.getCertificateChain();
const firstCertificateInChain = split_der(chain)[0];
return firstCertificateInChain!;
},
示例5: verifyX509UserIdentity
function verifyX509UserIdentity(
serverCertificate: Certificate,
sessionNonce: Buffer,
securityPolicy: SecurityPolicy,
userTokenPolicy: UserIdentityToken,
userIdentityToken: X509IdentityToken,
userTokenSignature: SignatureData,
callback: (err: null, statusCode: StatusCode) => void
) {
const cryptoFactory = getCryptoFactory(securityPolicy);
if (!cryptoFactory) {
return callback(null, StatusCodes.BadSecurityPolicyRejected);
}
if (!userTokenSignature || !userTokenSignature.signature) {
return callback(null, StatusCodes.BadUserSignatureInvalid);
}
if (userIdentityToken.policyId !== userTokenPolicy.policyId) {
console.log("invalid encryptionAlgorithm");
console.log("userTokenPolicy", userTokenPolicy.toString());
console.log("userTokenPolicy", userIdentityToken.toString());
return callback(null, StatusCodes.BadSecurityPolicyRejected);
}
const certificate = userIdentityToken.certificateData/* as Certificate*/;
const parts = split_der(certificate);
const nonce = sessionNonce;
assert(certificate instanceof Buffer, "expecting certificate to be a Buffer");
assert(nonce instanceof Buffer, "expecting nonce to be a Buffer");
assert(userTokenSignature.signature instanceof Buffer, "expecting userTokenSignature to be a Buffer");
// verify proof of possession by checking certificate signature & server nonce correctness
if (!verifySignature(serverCertificate, nonce, userTokenSignature, certificate, securityPolicy)) {
return callback(null, StatusCodes.BadUserSignatureInvalid);
}
return callback(null, StatusCodes.Good);
}
示例6: getSignatureLength
public getSignatureLength(): PublicKeyLength {
const chain = this.getCertificateChain();
const firstCertificateInChain = split_der(chain)[0];
const cert = exploreCertificateInfo(firstCertificateInChain);
return cert.publicKeyLength; // 1024 bits = 128Bytes or 2048=256Bytes
}
示例7: replaceServerCertificateUsingPushCertificateManagerMethod
async function replaceServerCertificateUsingPushCertificateManagerMethod(endpointUrl: string): Promise<Certificate> {
const client = OPCUAClient.create({
certificateFile: clientCertificateFile,
privateKeyFile: clientPrivateKeyFile,
securityMode: MessageSecurityMode.SignAndEncrypt,
securityPolicy: SecurityPolicy.Basic256
});
try {
await client.connect(endpointUrl);
const userIdentityToken: UserIdentityInfoUserName = {
type: UserTokenType.UserName,
password: "secret",
userName: "admin"
};
const session = await client.createSession(userIdentityToken);
const pm = new ClientPushCertificateManagement(session);
const response = await pm.createSigningRequest(
"DefaultApplicationGroup",
NodeId.nullNodeId,
"CN=MyApplication");
debugLog(" cert request status",
response.statusCode.toString());
if (response.statusCode !== StatusCodes.Good) {
throw new Error("Cannot get signing request from server : " + response.statusCode.toString());
}
debugLog(" cert request ",
response.certificateSigningRequest!.toString("base64"));
const certificateFull = await produceCertificate(response.certificateSigningRequest!);
const certificateChain = split_der(certificateFull);
const certificate = certificateChain[0];
const issuerCertificates = certificateChain.slice(1);
// generate some certificate
const response2 = await pm.updateCertificate(
"DefaultApplicationGroup",
NodeId.nullNodeId,
certificate,
issuerCertificates
);
debugLog(" updateCertificate status", response2.statusCode.toString());
if (response2.statusCode !== StatusCodes.Good) {
throw new Error("Cannot updateCertificate " + response2.statusCode.toString());
}
await pm.applyChanges();
await session.close();
return certificateFull;
} catch (err) {
console.log("err =", err);
throw err;
} finally {
await client.disconnect();
}
}