Permalink
Browse files

added some example files

  • Loading branch information...
1 parent 89c2691 commit c2c92f17a4cd29940bd400a8460ab5ed13311358 @tjgillies tjgillies committed Jan 29, 2011
Showing with 113 additions and 0 deletions.
  1. +50 −0 node.js/message.js
  2. +20 −0 node.js/mycert.pem
  3. +15 −0 node.js/mykey.pem
  4. +28 −0 node.js/send.js
View
@@ -0,0 +1,50 @@
+var dgram = require('dgram');
+var message = new Buffer(JSON.stringify({"+end":"38666817e1b38470644e004b9356c1622368fa57"}));
+var socket = dgram.createSocket("udp4");
+var crypto = require('crypto');
+
+socket.sendData = function(message){ console.log(message.toString()); this.send(message, 0, message.length, 42424, "telehash.org"); }
+
+socket.on("message", function(data, rinfo){
+ console.log(data.toString());
+ console.log("message");
+ telex = JSON.parse(data.toString());
+ //console.log("TELEX: " + JSON.stringify(telex));
+ if (telex["_ring"]){
+ ring = telex["_ring"];
+ console.log("LINE: " + ring);
+ var response = new Buffer(JSON.stringify({".tap":[{"has":["+key"]}],"_line":ring, "_to":"208.68.163.247:42424"}));
+ this.sendData(response);
+ }
+ if (telex["+key"]){
+ console.log("INCOMING KEY!!!!!!!!");
+ var message = telex["+message"];
+ var key = telex["+key"];
+ //console.log(key);
+ var signature = telex["+sig"];
+ var verifier = crypto.createVerify('RSA-SHA1');
+ verifier.update(message);
+ //console.log(message);
+ var bool =verifier.verify(key, signature, signature_format='hex');
+ //console.log(bool);
+ if (bool){
+ console.log("Key validates");
+ } else {
+ console.log("Key doesn't validate");
+ }
+
+ }
+});
+
+socket.on("listening", function(){
+ console.log("Now listening");
+ //othersocket = dgram.createSocket("udp4");
+ //othersocket.send(message, 0, message.length, 42424, "telehash.org");
+ socket.send(message, 0, message.length, 42424, "telehash.org");
+
+});
+
+socket.bind(12345);
+
+
+
View
@@ -0,0 +1,20 @@
+-----BEGIN CERTIFICATE-----
+MIIDXDCCAsWgAwIBAgIJAKL0UG+mRkSPMA0GCSqGSIb3DQEBBQUAMH0xCzAJBgNV
+BAYTAlVLMRQwE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wJEL1VenQHiVYlWWtqXBThe9ggqRPnCfsCRTP8qifKkjk45zWPcpN
+-----END CERTIFICATE-----
View
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQDx3wdzpq2rvwm3Ucun1qAD/ClB+wW+RhR1nVix286QvaNqePAd
+CAwwLL82NqXcVQRbQ4s95splQnwvjgkFdKVXFTjPKKJI5aV3wSRN61EBVPdYpCre
+535yfG/uDysZFCnVQdnCZ1tnXAR8BirxCNjHqbVyIyBGjsNoNCEPb2R35QIDAQAB
+AoGBAJNem9C4ftrFNGtQ2DB0Udz7uDuucepkErUy4MbFsc947GfENjDKJXr42Kx0
+kYx09ImS1vUpeKpH3xiuhwqe7tm4FsCBg4TYqQle14oxxm7TNeBwwGC3OB7hiokb
+aAjbPZ1hAuNs6ms3Ybvvj6Lmxzx42m8O5DXCG2/f+KMvaNUhAkEA/ekrOsWkNoW9
+2n3m+msdVuxeek4B87EoTOtzCXb1dybIZUVv4J48VAiM43hhZHWZck2boD/hhwjC
+M5NWd4oY6QJBAPPcgBVNdNZSZ8hR4ogI4nzwWrQhl9MRbqqtfOn2TK/tjMv10ALg
+lPmn3SaPSNRPKD2hoLbFuHFERlcS79pbCZ0CQQChX3PuIna/gDitiJ8oQLOg7xEM
+wk9TRiDK4kl2lnhjhe6PDpaQN4E4F0cTuwqLAoLHtrNWIcOAQvzKMrYdu1MhAkBm
+Et3qDMnjDAs05lGT72QeN90/mPAcASf5eTTYGahv21cb6IBxM+AnwAPpqAAsHhYR
+9h13Y7uYbaOjvuF23LRhAkBoI9eaSMn+l81WXOVUHnzh3ZwB4GuTyxMXXNOhuiFd
+0z4LKAMh99Z4xQmqSoEkXsfM4KPpfhYjF/bwIcP5gOei
+-----END RSA PRIVATE KEY-----
View
@@ -0,0 +1,28 @@
+var dgram = require('dgram');
+var crypto = require('crypto');
+var fs = require('fs');
+
+var keyPem = fs.readFileSync("mykey.pem", 'ascii');
+var pubKey = fs.readFileSync("mycert.pem", 'ascii');
+var cred = crypto.createCredentials({key:keyPem});
+var key = cred.key;
+var socket = dgram.createSocket("udp4");
+var signer = crypto.createSign('RSA-SHA1');
+var msg = "I like cheese";
+signer.update(msg);
+var signature = signer.sign(keyPem, output_format='hex');
+var json = {"+key":pubKey, "_hop":1,"+end":"8bf1cce916417d16b7554135b6b075fb16dd26ce","_to":"208.68.163.247:42424", "+sig":signature, "+message":msg};
+var message = new Buffer(JSON.stringify(json));
+
+console.log(message.toString());
+socket.on("listening",function(){
+ console.log("sending");
+ socket.send(message, 0, message.length, 42424, "telehash.org", function(){ setTimeout(process.exit,1000); });
+});
+
+socket.bind(34344);
+
+
+
+
+

0 comments on commit c2c92f1

Please sign in to comment.