/* * Copyright (c) 2014, GMO GlobalSign * Copyright (c) 2015, Peculiar Ventures * All rights reserved. * * Author 2014-2015, Yury Strozhevsky <www.strozhevsky.com>. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors * may be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. *
*/
( function(in_window)
{ //************************************************************************************** // #region Declaration of global variables //************************************************************************************** // #region "org" namespace if(typeof in_window.org === "undefined")
in_window.org = {}; else
{ if(typeof in_window.org !== "object") thrownew Error("Name org already exists and it's not an object");
} // #endregion
// #region "org.pkijs" namespace if(typeof in_window.org.pkijs === "undefined")
in_window.org.pkijs = {}; else
{ if(typeof in_window.org.pkijs !== "object") thrownew Error("Name org.pkijs already exists and it's not an object" + " but " + (typeof in_window.org.pkijs));
} // #endregion
// #region "org.pkijs.simpl" namespace if(typeof in_window.org.pkijs.simpl === "undefined")
in_window.org.pkijs.simpl = {}; else
{ if(typeof in_window.org.pkijs.simpl !== "object") thrownew Error("Name org.pkijs.simpl already exists and it's not an object" + " but " + (typeof in_window.org.pkijs.simpl));
} // #endregion
// #region "org.pkijs.simpl.x509" namespace if(typeof in_window.org.pkijs.simpl.x509 === "undefined")
in_window.org.pkijs.simpl.x509 = {}; else
{ if(typeof in_window.org.pkijs.simpl.x509 !== "object") thrownew Error("Name org.pkijs.simpl.x509 already exists and it's not an object" + " but " + (typeof in_window.org.pkijs.simpl.x509));
} // #endregion
// #region "local" namespace var local = {}; // #endregion //************************************************************************************** // #endregion //************************************************************************************** // #region Simplified structure for "Time" type //**************************************************************************************
in_window.org.pkijs.simpl.TIME = function()
{ // #region Internal properties of the object this.type = 0; // 0 - UTCTime; 1 - GeneralizedTime; 2 - empty value this.value = new Date(0, 0, 0); // #endregion
// #region If input argument array contains "schema" for this object if((arguments[0] instanceof Object) && ("schema" in arguments[0]))
in_window.org.pkijs.simpl.TIME.prototype.fromSchema.call(this, arguments[0].schema); // #endregion // #region If input argument array contains "native" values for internal properties else
{ if(arguments[0] instanceof Object)
{ this.type = (arguments[0].type || 0); this.value = (arguments[0].value || (new Date(0, 0, 0)));
}
} // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.TIME.prototype.fromSchema = function(schema)
{ // #region Check the schema is valid var asn1 = in_window.org.pkijs.compareSchema(schema,
schema,
in_window.org.pkijs.schema.TIME({
names: {
utcTimeName: "utcTimeName",
generalTimeName: "generalTimeName"
}
})
);
if(asn1.verified === false) thrownew Error("Object's schema was not verified against input data for TIME"); // #endregion
// #region Get internal properties from parsed schema if("utcTimeName" in asn1.result)
{ this.type = 0; this.value = asn1.result.utcTimeName.toDate();
} if("generalTimeName" in asn1.result)
{ this.type = 1; this.value = asn1.result.generalTimeName.toDate();
} // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.TIME.prototype.toSchema = function()
{ // #region Construct and return new ASN.1 schema for this object var result = {};
if(this.type === 0)
result = new in_window.org.pkijs.asn1.UTCTIME({ value_date: this.value }); if(this.type === 1)
result = new in_window.org.pkijs.asn1.GENERALIZEDTIME({ value_date: this.value });
return result; // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.TIME.prototype.toJSON = function()
{ return {
type: this.type,
value: this.value
};
}; //************************************************************************************** // #endregion //************************************************************************************** // #region Simplified structure for "GeneralName" type //**************************************************************************************
in_window.org.pkijs.simpl.GENERAL_NAME = function()
{ // #region Internal properties of the object this.NameType = 9; // Name type - from a tagged value (0 for "otherName", 1 for "rfc822Name" etc.) this.Name = {}; // #endregion
if(asn1.verified === false) thrownew Error("Object's schema was not verified against input data for GENERAL_NAME"); // #endregion
// #region Get internal properties from parsed schema this.NameType = asn1.result["block_name"].id_block.tag_number;
switch(this.NameType)
{ case 0: // otherName this.Name = asn1.result["block_name"]; break; case 1: // rfc822Name + dNSName + uniformResourceIdentifier case 2: case 6:
{ var value = asn1.result["block_name"];
return _object;
}; //************************************************************************************** // #endregion //************************************************************************************** // #region Simplified structure for "GeneralNames" type //**************************************************************************************
in_window.org.pkijs.simpl.GENERAL_NAMES = function()
{ // #region Internal properties of the object this.names = new Array(); // Array of "org.pkijs.simpl.GENERAL_NAME" // #endregion
// #region If input argument array contains "schema" for this object if((arguments[0] instanceof Object) && ("schema" in arguments[0]))
in_window.org.pkijs.simpl.GENERAL_NAMES.prototype.fromSchema.call(this, arguments[0].schema); // #endregion // #region If input argument array contains "native" values for internal properties else
{ if(arguments[0] instanceof Object)
{ this.names = arguments[0].names || new Array(); // Array of "org.pkijs.simpl.GENERAL_NAME"
}
} // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.GENERAL_NAMES.prototype.fromSchema = function(schema)
{ // #region Check the schema is valid var asn1 = in_window.org.pkijs.compareSchema(schema,
schema, new in_window.org.pkijs.asn1.SEQUENCE({
value: [ new in_window.org.pkijs.asn1.REPEATED({
name: "names",
value: in_window.org.pkijs.schema.GENERAL_NAME()
})
]
})
);
if(asn1.verified === false) thrownew Error("Object's schema was not verified against input data for GENERAL_NAMES"); // #endregion
// #region Get internal properties from parsed schema var n = asn1.result["names"];
for(var i = 0; i < n.length; i++) this.names.push(new in_window.org.pkijs.simpl.GENERAL_NAME({ schema: n[i] })); // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.GENERAL_NAMES.prototype.toSchema = function(schema)
{ // #region Construct and return new ASN.1 schema for this object var output_array = new Array();
for(var i = 0; i < this.names.length; i++)
output_array.push(this.names[i].toSchema());
return (new in_window.org.pkijs.asn1.SEQUENCE({
value: output_array
})); // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.GENERAL_NAMES.prototype.toJSON = function()
{ var _names = new Array();
for(var i = 0; i < this.names.length; i++)
_names.push(this.names[i].toJSON());
return {
names: _names
};
}; //************************************************************************************** // #endregion //************************************************************************************** // #region Simplified structure for "AlgorithmIdentifier" type //**************************************************************************************
in_window.org.pkijs.simpl.ALGORITHM_IDENTIFIER = function()
{ // #region Internal properties of the object this.algorithm_id = ""; // OPTIONAL this.algorithm_params = new in_window.org.pkijs.asn1.NULL(); // #endregion
// #region If input argument array contains "schema" for this object if((arguments[0] instanceof Object) && ("schema" in arguments[0]))
in_window.org.pkijs.simpl.ALGORITHM_IDENTIFIER.prototype.fromSchema.call(this, arguments[0].schema); // #endregion // #region If input argument array contains "native" values for internal properties else
{ if(arguments[0] instanceof Object)
{ this.algorithm_id = arguments[0].algorithm_id || ""; if("algorithm_params" in arguments[0]) this.algorithm_params = arguments[0].algorithm_params;
}
} // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.ALGORITHM_IDENTIFIER.prototype.fromSchema = function(schema)
{ // #region Check the schema is valid var asn1 = in_window.org.pkijs.compareSchema(schema,
schema,
in_window.org.pkijs.schema.ALGORITHM_IDENTIFIER({
names: {
algorithmIdentifier: "algorithm",
algorithmParams: "params"
}
})
);
if(asn1.verified === false) thrownew Error("Object's schema was not verified against input data for ALGORITHM_IDENTIFIER"); // #endregion
// #region Get internal properties from parsed schema this.algorithm_id = asn1.result.algorithm.value_block.toString(); if("params" in asn1.result) this.algorithm_params = asn1.result.params; // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.ALGORITHM_IDENTIFIER.prototype.toSchema = function()
{ // #region Create array for output sequence var output_array = new Array();
if(asn1.verified === false) thrownew Error("Object's schema was not verified against input data for RSASSA_PSS_params"); // #endregion
// #region Get internal properties from parsed schema if("hashAlgorithm" in asn1.result) this.hashAlgorithm = new in_window.org.pkijs.simpl.ALGORITHM_IDENTIFIER({ schema: asn1.result["hashAlgorithm"] });
if("maskGenAlgorithm" in asn1.result) this.maskGenAlgorithm = new in_window.org.pkijs.simpl.ALGORITHM_IDENTIFIER({ schema: asn1.result["maskGenAlgorithm"] });
if("saltLength" in asn1.result) this.saltLength = asn1.result["saltLength"].value_block.value_dec;
if("trailerField" in asn1.result) this.trailerField = asn1.result["trailerField"].value_block.value_dec; // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.x509.RSASSA_PSS_params.prototype.toSchema = function()
{ // #region Create array for output sequence var output_array = new Array();
// #region Construct and return new ASN.1 schema for this object return (new in_window.org.pkijs.asn1.SEQUENCE({
value: output_array
})); // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.x509.RSASSA_PSS_params.prototype.toJSON = function()
{ var _object = {};
if("hashAlgorithm" in this)
_object.hashAlgorithm = this.hashAlgorithm.toJSON();
if("maskGenAlgorithm" in this)
_object.maskGenAlgorithm = this.maskGenAlgorithm.toJSON();
if("saltLength" in this)
_object.saltLength = this.saltLength.toJSON();
if("trailerField" in this)
_object.trailerField = this.trailerField.toJSON();
return _object;
}; //************************************************************************************** // #endregion //************************************************************************************** // #region Simplified structure for "SubjectPublicKeyInfo" type //**************************************************************************************
in_window.org.pkijs.simpl.PUBLIC_KEY_INFO = function()
{ // #region Internal properties of the object this.algorithm = new in_window.org.pkijs.simpl.ALGORITHM_IDENTIFIER(); this.subjectPublicKey = new in_window.org.pkijs.asn1.BITSTRING(); // #endregion
// #region If input argument array contains "schema" for this object if((arguments[0] instanceof Object) && ("schema" in arguments[0]))
in_window.org.pkijs.simpl.PUBLIC_KEY_INFO.prototype.fromSchema.call(this, arguments[0].schema); // #endregion // #region If input argument array contains "native" values for internal properties else
{ if(arguments[0] instanceof Object)
{ this.algorithm = (arguments[0].algorithm || (new in_window.org.pkijs.simpl.ALGORITHM_IDENTIFIER())); this.subjectPublicKey = (arguments[0].subjectPublicKey || (new in_window.org.pkijs.asn1.BITSTRING()));
}
} // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.PUBLIC_KEY_INFO.prototype.fromSchema = function(schema)
{ // #region Check the schema is valid var asn1 = in_window.org.pkijs.compareSchema(schema,
schema,
in_window.org.pkijs.schema.PUBLIC_KEY_INFO({
names: {
algorithm: {
names: {
block_name: "algorithm"
}
},
subjectPublicKey: "subjectPublicKey"
}
})
);
if(asn1.verified === false) thrownew Error("Object's schema was not verified against input data for PUBLIC_KEY_INFO"); // #endregion
// #region Get internal properties from parsed schema this.algorithm = new in_window.org.pkijs.simpl.ALGORITHM_IDENTIFIER({ schema: asn1.result.algorithm }); this.subjectPublicKey = asn1.result.subjectPublicKey; // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.PUBLIC_KEY_INFO.prototype.toSchema = function()
{ // #region Construct and return new ASN.1 schema for this object return (new in_window.org.pkijs.asn1.SEQUENCE({
value: [ this.algorithm.toSchema(), this.subjectPublicKey
]
})); // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.PUBLIC_KEY_INFO.prototype.importKey = function(publicKey)
{ /// <param name="publicKey" type="Key">Public key to work with</param>
// #region Initial variables var sequence = Promise.resolve(); var _this = this; // #endregion
return _object;
}; //************************************************************************************** // #endregion //************************************************************************************** // #region Simplified structure for "RelativeDistinguishedName" type //**************************************************************************************
in_window.org.pkijs.simpl.RDN = function()
{ // #region Internal properties of the object /// <field name="types_and_values" type="Array" elementType="in_window.org.pkijs.simpl.ATTR_TYPE_AND_VALUE">Array of "type and value" objects</field> this.types_and_values = new Array(); /// <field name="value_before_decode" type="ArrayBuffer">Value of the RDN before decoding from schema</field> this.value_before_decode = new ArrayBuffer(0); // #endregion
// #region If input argument array contains "schema" for this object if((arguments[0] instanceof Object) && ("schema" in arguments[0]))
in_window.org.pkijs.simpl.RDN.prototype.fromSchema.call(this, arguments[0].schema); // #endregion // #region If input argument array contains "native" values for internal properties else
{ if(arguments[0] instanceof Object)
{ this.types_and_values = (arguments[0].types_and_values || (new Array())); this.value_before_decode = arguments[0].value_before_decode || new ArrayBuffer(0);
}
} // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.RDN.prototype.fromSchema = function(schema)
{ // #region Check the schema is valid var asn1 = in_window.org.pkijs.compareSchema(schema,
schema,
in_window.org.pkijs.schema.RDN({
names: {
block_name: "RDN",
repeated_set: "types_and_values"
}
})
);
if(asn1.verified === false) thrownew Error("Object's schema was not verified against input data for RDN"); // #endregion
// #region Get internal properties from parsed schema if("types_and_values" in asn1.result) // Could be a case when there is no "types and values"
{ var types_and_values_array = asn1.result.types_and_values; for(var i = 0; i < types_and_values_array.length; i++) this.types_and_values.push(new in_window.org.pkijs.simpl.ATTR_TYPE_AND_VALUE({ schema: types_and_values_array[i] }));
}
this.value_before_decode = asn1.result.RDN.value_before_decode; // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.RDN.prototype.toSchema = function()
{ // #region Decode stored TBS value if(this.value_before_decode.byteLength === 0) // No stored encoded array, create "from scratch"
{ // #region Create array for output set var output_array = new Array();
for(var i = 0; i < this.types_and_values.length; i++)
output_array.push(this.types_and_values[i].toSchema()); // #endregion
// #region Construct and return new ASN.1 schema for this object return (new in_window.org.pkijs.asn1.SEQUENCE({
value: output_array
})); // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.x509.AuthorityKeyIdentifier.prototype.toJSON = function()
{ var _object = {};
if("keyIdentifier" in this)
_object.keyIdentifier = this.keyIdentifier.toJSON();
if("authorityCertIssuer" in this)
{
_object.authorityCertIssuer = new Array();
for(var i = 0; i < this.authorityCertIssuer.length; i++)
_object.authorityCertIssuer.push(this.authorityCertIssuer[i].toJSON());
}
if("authorityCertSerialNumber" in this)
_object.authorityCertSerialNumber = this.authorityCertSerialNumber.toJSON();
return _object;
}; //************************************************************************************** // #endregion //************************************************************************************** // #region Simplified structure for "PrivateKeyUsagePeriod" type of extension //**************************************************************************************
in_window.org.pkijs.simpl.x509.PrivateKeyUsagePeriod = function()
{ // #region Internal properties of the object // OPTIONAL this.notBefore - new Date() // OPTIONAL this.notAfter - new Date() // #endregion
// #region If input argument array contains "schema" for this object if((arguments[0] instanceof Object) && ("schema" in arguments[0]))
in_window.org.pkijs.simpl.x509.PrivateKeyUsagePeriod.prototype.fromSchema.call(this, arguments[0].schema); // #endregion // #region If input argument array contains "native" values for internal properties else
{ if(arguments[0] instanceof Object)
{ if("notBefore" in arguments[0]) this.notBefore = arguments[0].notBefore;
if("notAfter" in arguments[0]) this.notAfter = arguments[0].notAfter;
}
} // #endregion
}; //**************************************************************************************
in_window.org.pkijs.simpl.x509.PrivateKeyUsagePeriod.prototype.fromSchema = function(schema)
{ // #region Check the schema is valid var asn1 = in_window.org.pkijs.compareSchema(schema,
schema,
in_window.org.pkijs.schema.x509.PrivateKeyUsagePeriod({
names: {
notBefore: "notBefore",
notAfter: "notAfter"
}
})
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.