diff options
author | Minteck <contact@minteck.org> | 2022-10-18 08:59:09 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-10-18 08:59:09 +0200 |
commit | 2c4ae43e688a9873e86211ea0e7aeb9ba770dd77 (patch) | |
tree | 17848d95522dab25d3cdeb9c4a6450e2a234861f /alarm/node_modules/node-forge/tests/ws-webid.js | |
parent | 108525534c28013cfe1897c30e4565f9893f3766 (diff) | |
download | pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.gz pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.bz2 pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.zip |
Update
Diffstat (limited to 'alarm/node_modules/node-forge/tests/ws-webid.js')
-rw-r--r-- | alarm/node_modules/node-forge/tests/ws-webid.js | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/alarm/node_modules/node-forge/tests/ws-webid.js b/alarm/node_modules/node-forge/tests/ws-webid.js new file mode 100644 index 0000000..2ce5816 --- /dev/null +++ b/alarm/node_modules/node-forge/tests/ws-webid.js @@ -0,0 +1,132 @@ +var websocket_webid = function(host, port) +{ + var cat = 'ws'; + + // TODO: get private key and certificate from local storage + var privateKey = + '-----BEGIN RSA PRIVATE KEY-----\r\n' + +'MIICXAIBAAKBgQCTmE8QLARsC57Z1OrOaLM6AS3fn70N7BvlU7z7yw8UpcJA/jOl\r\n' + +'NWu7eS9uzuckdVZ9FE0+x3DRvhtDI6K+18dcrUWtl5ADWXcs1QS3/7bGh7IybFyY\r\n' + +'0xT4VzLHcx6K4PNmfkjAQdyOz/EsuRqZ/ngIQ2tdHdkkzdQPECbTvFeG2wIDAQAB\r\n' + +'AoGAds3l7l2QHaxo7GzfqNBMXEdwto2tLxS8C6eQ+pkkBXm72HcF+Vj75AcTMD2p\r\n' + +'fwZYXQxHdV4yqRI+fZeku7uTA/3yBAAvNobbEN5jtHnq0ZTO/HO8HuHkKrCvD8c3\r\n' + +'0rJV6lNIuaARI9jZFf6HVchW3PMjKUpYhTs/sFhRxmsMpTkCQQDu8TPzXRmN1aw8\r\n' + +'tSI2Nyn8QUy9bw/12tlVaZIhrcVCiJl7JHGqSCowTqZlwmJIjd4W0zWjTvS7tEeO\r\n' + +'FaZHtP8lAkEAniGvm8S9zyzmhWRRIuU6EE2dtTbeAa5aSOK3nBaaNu2cHUxWle+J\r\n' + +'8lE4uequ9wqDG1AfOLobPmHReccmOI6N/wJAIP/I1/RkohT/a4bsiaZGsyLlkUf0\r\n' + +'YVTvLP+ege44zv6Ei+A1nnnG8dL64hTdc/27zVUwFDTEUeQM+c99nmudzQJBAApY\r\n' + +'qeTHOqQTjAGuTqC53tKyQV9Z96yke8PJEbpkwDJX2Z8RH5kv0xbHua5wbII9bdab\r\n' + +'p29OvfmW7N3K6fVJXoECQHK8FDC0i8v1Ui8FoBmt+Z1c1+/9TCEE0abUQ6rfOUbm\r\n' + +'XHMMac/n4qDs0OoCjR4u46dpoK+WN7zcg56tToFPVow=\r\n' + +'-----END RSA PRIVATE KEY-----'; + var certificate = + '-----BEGIN CERTIFICATE-----\r\n' + +'MIICgDCCAemgAwIBAgIBATANBgkqhkiG9w0BAQUFADBYMRMwEQYDVQQDEwpKb2hu\r\n' + +'IFNtaXRoMRMwEQYDVQQHEwpCbGFja3NidXJnMREwDwYDVQQIEwhWaXJnaW5pYTEL\r\n' + +'MAkGA1UEBhMCVVMxDDAKBgNVBAoTA0ZvbzAeFw0xMDExMjYxNzUxMzJaFw0xMTEx\r\n' + +'MjYxNzUxMzJaMFgxEzARBgNVBAMTCkpvaG4gU21pdGgxEzARBgNVBAcTCkJsYWNr\r\n' + +'c2J1cmcxETAPBgNVBAgTCFZpcmdpbmlhMQswCQYDVQQGEwJVUzEMMAoGA1UEChMD\r\n' + +'Rm9vMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCTmE8QLARsC57Z1OrOaLM6\r\n' + +'AS3fn70N7BvlU7z7yw8UpcJA/jOlNWu7eS9uzuckdVZ9FE0+x3DRvhtDI6K+18dc\r\n' + +'rUWtl5ADWXcs1QS3/7bGh7IybFyY0xT4VzLHcx6K4PNmfkjAQdyOz/EsuRqZ/ngI\r\n' + +'Q2tdHdkkzdQPECbTvFeG2wIDAQABo1owWDAMBgNVHRMEBTADAQH/MAsGA1UdDwQE\r\n' + +'AwIC9DA7BgNVHREENDAyhjBodHRwOi8vd2ViaWQuZGlnaXRhbGJhemFhci5jb20v\r\n' + +'aWRzLzE1MzQ1NzI2NDcjbWUwDQYJKoZIhvcNAQEFBQADgYEAPNm8albI4w6anynw\r\n' + +'XE/+00sCVks9BbgTcIpRqZPGqSuTRwoYW35isNLDqFqIUdVREMvFrEn3nOlOyKi0\r\n' + +'29G8JtLHFSXZsqf38Zou/bGAhtEH1AVEbM2bRtEnG8IW24jL8hiciz4htxmjnkHN\r\n' + +'JnQ8SQtUSWplGnz0vMFEOv6JbnI=\r\n' + +'-----END CERTIFICATE-----'; + + // create websocket + var ws = new WebSocket('ws://' + host + ':' + port); + forge.log.debug(cat, 'Created WebSocket', ws); + + // create TLS client + var success = false; + var tls = forge.tls.createConnection( + { + server: false, + caStore: [], + sessionCache: {}, + // supported cipher suites in order of preference + cipherSuites: [ + forge.tls.CipherSuites.TLS_RSA_WITH_AES_128_CBC_SHA, + forge.tls.CipherSuites.TLS_RSA_WITH_AES_256_CBC_SHA], + virtualHost: host, + verify: function(c, verified, depth, certs) + { + forge.log.debug(cat, + 'TLS Client verifying certificate w/CN: \"' + + certs[0].subject.getField('CN').value + '\"'); + // accept any certificate from the server for this test + return true; + }, + connected: function(c) + { + forge.log.debug(cat, 'Client connected'); + }, + getCertificate: function(c, hint) + { + forge.log.debug(cat, 'Client using client-certificate'); + return certificate; + }, + getPrivateKey: function(c, cert) + { + return privateKey; + }, + tlsDataReady: function(c) + { + // send base64-encoded TLS data to server + ws.send(forge.util.encode64(c.tlsData.getBytes())); + }, + dataReady: function(c) + { + var response = c.data.getBytes(); + forge.log.debug(cat, 'Client received \"' + response + '\"'); + try + { + response = JSON.parse(response); + success = response.success; + + // TODO: call window.authenticate on response json, just like + // w/flash version + } + catch(ex) {} + c.close(); + }, + closed: function(c) + { + forge.log.debug(cat, 'Client disconnected'); + if(success) + { + forge.log.debug(cat, 'PASS'); + } + else + { + forge.log.debug(cat, 'FAIL'); + } + }, + error: function(c, error) + { + forge.log.debug(cat, 'Client error: ' + error.message); + } + }); + + ws.onopen = function(evt) + { + forge.log.debug(cat, 'WebSocket connected'); + + // do TLS handshake + tls.handshake(); + }; + ws.onmessage = function(evt) + { + // base64-decode data and process it + tls.process(forge.util.decode64(evt.data)); + }; + ws.onclose = function(evt) + { + forge.log.debug(cat, 'WebSocket closed'); + }; +}; + |