Skip to content

Commit

Permalink
work on readSingleNode
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Feb 19, 2014
1 parent 26f91d1 commit 26a28eb
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 8 deletions.
21 changes: 20 additions & 1 deletion lib/opcua-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ OPCUAServer.prototype.on_request = function(request,channel,endpoint) {
}

};

OPCUAServer.prototype.getSignedCertificate = function() {

var self = this;
return new s.SignedSoftwareCertificate({
certificateData: self.getCertificate(),
signature: new Buffer("HelloWorld")
});
};


// session services
OPCUAServer.prototype._on_CreateSessionRequest = function(request,channel) {

Expand All @@ -195,9 +206,17 @@ OPCUAServer.prototype._on_CreateSessionRequest = function(request,channel) {
serverEndpoints: null,

// SignedSoftwareCertificate: The software certificates owned by the server.
serverSoftwareCertificates: null,
serverSoftwareCertificates: [
server.getSignedCertificate()
],

// SignatureData : A signature created with the server certificate.
//
// This is a signature generated with the private key associated with the
// serverCertificate. This parameter is calculated by appending the clientNonceto the
// clientCertificateand signing the resulting sequence of bytes.
// The SignatureAlgorithmshall be the asymmetricSignaturealgorithm specified in the
// SecurityPolicyfor the Endpoint
serverSignature: null,

// The maximum message size accepted by the server
Expand Down
60 changes: 56 additions & 4 deletions lib/server/server_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,74 @@ ServerEngine.prototype.readSingleNode = function (nodeId,attributeId) {
// QualifiedName
options.value = { dataType: DataType.QualifiedName, value:
{ name: obj.browseName , namespaceIndex: 0 }
}
};
break;
case AttributeIds.DisplayName:
options.value = { dataType: DataType.LocalizedText, value: obj.displayName[0] }
options.value = { dataType: DataType.LocalizedText, value: obj.displayName[0] };
break;
case AttributeIds.Description:
options.value = { dataType: DataType.String, value: obj.description || "no description" };
break;
case AttributeIds.WriteMask:
console.log(" warning ContainsNoLoops not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
break;
case AttributeIds.IsAbstract:
options.value = { dataType: DataType.Boolean, value: obj.isAbstract ? true:false };
break;
case AttributeIds.UserWriteMask:
options.value = { dataType: DataType.UInt32, value: 0 };
break;
case AttributeIds.Symmetric:
options.value = { dataType: DataType.Boolean, value: obj.symmetric ? true: false };
break;
case AttributeIds.InverseName:
options.value = { dataType: DataType.String, value: obj.inverseName || "<NO INVERSE NAME>" };
break;
case AttributeIds.ContainsNoLoops:
console.log(" warning ContainsNoLoops not implemented");
options.value = { dataType: DataType.Boolean, value: true };
break;
case AttributeIds.Value:
if (obj.hasOwnProperty("value")) {
assert(obj.value._schema.name == "Variant");
options.value = obj.value;
} else {

console.log(" warning Value not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
}
break;
case AttributeIds.EventNotifier:
console.log(" warning EventNotifier not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
break;
case AttributeIds.DataType:
console.log(" warning DataType not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
break;
case AttributeIds.ValueRank:
console.log(" warning ValueRank not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
break; case AttributeIds.ArrayDimensions:
case AttributeIds.AccessLevel:
console.log(" warning AccessLevel not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
break; case AttributeIds.UserAccessLevel:
case AttributeIds.MinimumSamplingInterval:
console.log(" warning MinimumSamplingInterval not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
break; case AttributeIds.Historizing:
case AttributeIds.Executable:
console.log(" warning Executable not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
break;
case AttributeIds.UserExecutable:
console.log(" warning UserExecutable not implemented");
options.value = { dataType: DataType.UInt32, value: 0 };
break;
default:
// may be return Bad_AttributeIdInvalid in dataValue instead ?
throw new Error(" Not implemented yet");
throw new Error(" Not implemented yet attributeId="+attributeId , util.inspect(obj,{colors:true}));
break;

}
Expand Down
4 changes: 3 additions & 1 deletion lib/server/server_secure_channel_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ServerSecureChannelLayer() {

var self = this ;
self.protocolVersion = 1;
self.timeout = 1000; // connection timeout
self.timeout = 2000; // connection timeout

self._current_requestId = NO_PENDING_REQUEST;

Expand Down Expand Up @@ -118,6 +118,8 @@ ServerSecureChannelLayer.prototype.send_response = function(msgType,responseMess

responseMessage.responseHeader.requestHandle = self._current_requestId;

debugLog(util.inspect(responseMessage,{colors:true,depth:10}));

self.messageChunker.chunkSecureMessage(msgType,options,responseMessage,function(messageChunk){

if (messageChunk) {
Expand Down
2 changes: 1 addition & 1 deletion lib/session_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var CreateSessionResponse_Schema = {
//xx { name:"serverCertificate", fieldType:"ApplicationInstanceCertificate", documentation: "The application certificate for the server."},
{ name:"serverEndpoints", isArray:true,fieldType:"EndpointDescription", documentation: "The endpoints provided by the server."},
{ name:"serverSoftwareCertificates", isArray:true,fieldType:"SignedSoftwareCertificate", documentation: "The software certificates owned by the server."},
{ name:"serverSignature", fieldType:"SignatureData", documentation: "A signature created with the server certificate."},
{ name:"serverSignature", fieldType:"SignatureData", documentation: "A signature created with the server certificate.", defaultValue:"null"},
{ name:"maxRequestMessageSize", fieldType:"UInt32", documentation: "The maximum message size accepted by the server."}

]
Expand Down
10 changes: 9 additions & 1 deletion test/test_crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ var hexy = require("hexy");
// openssl req -x509 -days 365 -nodes -newkey rsa:1024 -keyout key.pem -out cert.pem
// generate public key from private.key
// openssl rsa -in key.pem -pubout > public_key.pub will extract the public key and print that out.

//
// converting der to pem files:
// openssl x509 -inform DER -outform PEM -text -in der-certificate-file -out pem-certificate-file
//
// converting pem to der files:
// openssl rsa -inform DER -outform PEM -in der-rsa-key-file -out pem-rsa-key-file
//
// If you have .pfx certificates you can convert them to .pem using openssl:
//openssl pkcs12 -in cert.pfx -out cert.pem
var doDebug = false;
// doDebug = true;
function debugLog() {
Expand Down

0 comments on commit 26a28eb

Please sign in to comment.