mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
parent
f88d3063fe
commit
db06ec1975
37 changed files with 28174 additions and 44 deletions
26
rdp/security/index.js
Normal file
26
rdp/security/index.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2014-2015 Sylvain Peyrefitte
|
||||
*
|
||||
* This file is part of node-rdpjs.
|
||||
*
|
||||
* node-rdpjs is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var x509 = require('./x509');
|
||||
var rsa = require('./rsa');
|
||||
|
||||
module.exports = {
|
||||
x509 : x509,
|
||||
rsa : rsa
|
||||
};
|
1543
rdp/security/jsbn.js
Normal file
1543
rdp/security/jsbn.js
Normal file
File diff suppressed because it is too large
Load diff
43
rdp/security/rsa.js
Normal file
43
rdp/security/rsa.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2014-2015 Sylvain Peyrefitte
|
||||
*
|
||||
* This file is part of node-rdpjs.
|
||||
*
|
||||
* node-rdpjs is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var BigInteger = require('./jsbn');
|
||||
|
||||
/**
|
||||
* @param modulus {Buffer}
|
||||
* @param pubExp {integer}
|
||||
*/
|
||||
function publicKey(modulus, pubExp) {
|
||||
return {
|
||||
n : modulus,
|
||||
e : pubExp
|
||||
}
|
||||
}
|
||||
|
||||
function encrypt(data, publicKey) {
|
||||
return new BigInteger(data).modPowInt(publicKey.e, new BigInteger(publicKey.n)).toBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Module Export
|
||||
*/
|
||||
module.exports = {
|
||||
publicKey : publicKey,
|
||||
encrypt : encrypt
|
||||
};
|
216
rdp/security/x509.js
Normal file
216
rdp/security/x509.js
Normal file
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
* Copyright (c) 2014-2015 Sylvain Peyrefitte
|
||||
*
|
||||
* This file is part of node-rdpjs.
|
||||
*
|
||||
* node-rdpjs is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// https://tools.ietf.org/html/rfc5280
|
||||
|
||||
var asn1 = require('../asn1');
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 20
|
||||
* @returns {asn1.univ.Choice}
|
||||
*/
|
||||
function DirectoryString() {
|
||||
return new asn1.univ.Choice({
|
||||
teletexString : new asn1.univ.T61String(),
|
||||
printableString : new asn1.univ.PrintableString(),
|
||||
universalString : new asn1.univ.UniversalString(),
|
||||
utf8String : new asn1.univ.UTF8String(),
|
||||
bmpString : new asn1.univ.BMPString(),
|
||||
ia5String : new asn1.univ.IA5String()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc5280 page 20
|
||||
* @returns {asn1.univ.Choice}
|
||||
*/
|
||||
function AttributeValue() {
|
||||
return DirectoryString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 20
|
||||
* @returns {asn1.univ.ObjectIdentifier}
|
||||
*/
|
||||
function AttributeType() {
|
||||
return new asn1.univ.ObjectIdentifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 20
|
||||
* @returns {asn1.univ.Sequence}
|
||||
*/
|
||||
function AttributeTypeAndValue() {
|
||||
return new asn1.univ.Sequence({
|
||||
type : AttributeType(),
|
||||
value : AttributeValue()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc5280 page 116
|
||||
* @returns {asn1.univ.SetOf}
|
||||
*/
|
||||
function RelativeDistinguishedName() {
|
||||
return new asn1.univ.SetOf(AttributeTypeAndValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc5280 page 116
|
||||
* @returns {asn1.univ.SequenceOf}
|
||||
*/
|
||||
function RDNSequence() {
|
||||
return new asn1.univ.SequenceOf(RelativeDistinguishedName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 116
|
||||
* @returns {asn1.univ.Choice}
|
||||
*/
|
||||
function Name() {
|
||||
return new asn1.univ.Choice({
|
||||
rdnSequence : RDNSequence()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 18
|
||||
* @returns {asn1.univ.Sequence}
|
||||
*/
|
||||
function AlgorithmIdentifier() {
|
||||
return new asn1.univ.Sequence({
|
||||
algorithm : new asn1.univ.ObjectIdentifier(),
|
||||
parameters : new asn1.univ.Null()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 117
|
||||
* @returns {asn1.univ.Sequence}
|
||||
*/
|
||||
function Extension() {
|
||||
return new asn1.univ.Sequence({
|
||||
extnID : new asn1.univ.ObjectIdentifier(),
|
||||
critical : new asn1.univ.Boolean(),
|
||||
extnValue : new asn1.univ.OctetString()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 117
|
||||
* @returns {asn1.univ.SequenceOf}
|
||||
*/
|
||||
function Extensions() {
|
||||
return new asn1.univ.SequenceOf(Extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 117
|
||||
* @returns {asn1.univ.Choice}
|
||||
*/
|
||||
function Time() {
|
||||
return new asn1.univ.Choice({
|
||||
utcTime : new asn1.univ.UTCTime(),
|
||||
generalTime : new asn1.univ.GeneralizedTime()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 117
|
||||
* @returns {asn1.univ.Sequence}
|
||||
*/
|
||||
function Validity() {
|
||||
return new asn1.univ.Sequence({
|
||||
notBefore : Time(),
|
||||
notAfter : Time()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 117
|
||||
* @returns {asn1.univ.Integer}
|
||||
*/
|
||||
function CertificateSerialNumber() {
|
||||
return new asn1.univ.Integer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 117
|
||||
* @returns {asn1.univ.Sequence}
|
||||
*/
|
||||
function SubjectPublicKeyInfo() {
|
||||
return new asn1.univ.Sequence({
|
||||
algorithm : AlgorithmIdentifier(),
|
||||
subjectPublicKey : new asn1.univ.BitString()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 117
|
||||
* @returns {asn1.univ.BitString}
|
||||
*/
|
||||
function UniqueIdentifier() {
|
||||
return new asn1.univ.BitString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 117
|
||||
* @returns {asn1.univ.Sequence}
|
||||
*/
|
||||
function TbsCertificate() {
|
||||
return new asn1.univ.Sequence({
|
||||
version : CertificateSerialNumber().explicitTag(new asn1.spec.Asn1Tag(asn1.spec.TagClass.Context, asn1.spec.TagFormat.Constructed, 0)),
|
||||
serialNumber : new asn1.univ.Integer(),
|
||||
signature : AlgorithmIdentifier(),
|
||||
issuer : Name(),
|
||||
validity : Validity(),
|
||||
subject : Name(),
|
||||
subjectPublicKeyInfo : SubjectPublicKeyInfo(),
|
||||
issuerUniqueID : UniqueIdentifier().implicitTag(asn1.spec.TagClass.Context, asn1.spec.TagFormat.Primitive, 1).optional(),
|
||||
subjectUniqueID : UniqueIdentifier().implicitTag(asn1.spec.TagClass.Context, asn1.spec.TagFormat.Primitive, 2).optional(),
|
||||
extensions : Extensions().implicitTag(asn1.spec.TagClass.Context, asn1.spec.TagFormat.Primitive, 3).optional()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc5280 page 117
|
||||
* @returns {asn1.univ.Sequence}
|
||||
*/
|
||||
function X509Certificate() {
|
||||
return new asn1.univ.Sequence({
|
||||
tbsCertificate : TbsCertificate(),
|
||||
signatureAlgorithm : AlgorithmIdentifier(),
|
||||
signatureValue : new asn1.univ.BitString()
|
||||
});
|
||||
}
|
||||
|
||||
function RSAPublicKey() {
|
||||
return new asn1.univ.Sequence({
|
||||
modulus : new asn1.univ.Integer(),
|
||||
publicExponent : new asn1.univ.Integer()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Module Export
|
||||
*/
|
||||
module.exports = {
|
||||
X509Certificate : X509Certificate,
|
||||
RSAPublicKey : RSAPublicKey
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue