Skip to content

Commit

Permalink
chore: add lab for securing sip.js with jwt tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Feb 26, 2024
1 parent 4ff276c commit ef2cbd1
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
22 changes: 22 additions & 0 deletions securing_sipjs_with_ephemeral_agents/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3"

services:
routr:
image: fonoster/routr-one:latest
environment:
EXTERNAL_ADDRS: ${DOCKER_HOST_ADDRESS}
CONNECT_VERIFIER_PUBLIC_KEY_PATH: /keys/public.key
ports:
- 51908:51908
- 5062:5062
volumes:
- shared:/var/lib/postgresql/data
- ./work/public.key:/keys/public.key

simplephone:
image: psanders/simplephone:latest
ports:
- 8080:8080

volumes:
shared:
19 changes: 19 additions & 0 deletions securing_sipjs_with_ephemeral_agents/work/create-jwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require("fs");
const jwt = require("jsonwebtoken");

const privateKey = fs.readFileSync("private.key");

const payload = {
ref: "agent-01",
domainRef: "domain-01",
aor: "sip:[email protected]",
aorLink: "sip:[email protected]",
domain: "sip.local",
privacy: "NONE",
allowedMethods: ["INVITE", "REGISTER"]
};

const signOptions = { expiresIn: "1h", algorithm: "RS256" };
const token = jwt.sign(payload, privateKey, signOptions);

console.log("Token: " + token);
158 changes: 158 additions & 0 deletions securing_sipjs_with_ephemeral_agents/work/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions securing_sipjs_with_ephemeral_agents/work/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "tokens",
"version": "1.0.0",
"description": "",
"main": "create-jwt.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"jsonwebtoken": "^9.0.2"
}
}
52 changes: 52 additions & 0 deletions securing_sipjs_with_ephemeral_agents/work/private.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCzHTRq2j9vqy9q
5JlFsF258GadUL5RhL2UBev10VnCpMaYD9tEp8K+o+x8MLbDD7B82UPyxsvUS9KE
y1Kxuv7ImmAgUmBO0QdN6joLDa48O60KfoTwkN0S54WeBL5p2/2L2UfZydqUby9L
JDj39veHWfMEz8XuvgFTFj9vGjPdh7kWdKRXuK9El1VJveJqa4toMWf+plLcNXyG
IbOcYCWHzmexZb8gOLRzo2G+/DHTM14siLt4m6O5eN/HMZj8GmtkWWnwmf4eHyuD
dAxUW10HThswJ9cThXaSu1WH20I/OwthunFwx3XB2lcimAOMgE2J/TAu1z1ZRkdT
QfOjHuyoqfDp9BRZ6PtvdJL8Nc7q4DvCmjzQlJWRusNIaspj0wuq7fOv0TMezP9U
Hj1CsgGTeaUUOQDfpAeMlqqd+prgCjXi0SIwMV+0RvreBM/3YK4BNYSUpjkYA1A0
vxKiXizbvFb8D7k6BUBVvJbM6aTfHhUoAeRS29s/yKfZ1o+mARZ3GV6sXx1cG0ya
3n3dtECxqupxSEIUu3EUUDoEqvGD6Wqc5OE/4gcHtP2AadxRMKS4GDawNWGTGbNJ
YUz51+aRNzJjWbLh+u3t7DyW4yISCLcc5l3TO9cW6AW91C4m/zcSR4+tX2IkxnBd
55j9rXnjknNKg0K7VSYyZYhBVJOIlwIDAQABAoICABoaCu35YR42XaIfryBjO71h
haquPhXmGLRuCn1XpVOCrLgzM1p1ciFTBR7yAGg7rJX9GXRTORf2drbIZIQnAoMc
UB7Vslg6COz3Ub8Tns0DS0vItTnTeowLNkMZYOBPYUsUfm6EBnj0HPm/zReBo3/T
gWE1oBwTD2Fa0CKyOFWztirKE7r+3HfL7+9fnxOwGXA1JvkKpu+VUdDAL4r9zep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FKcynzCR+I7ws5aZpLH8rE6SpwzTYL/26rkQIXPwvWvt7MvcQ5NPEVk7ZLczL3G2
glqb37hQ6CniwbebwW5eHy5YLnYdCXs=
-----END PRIVATE KEY-----
14 changes: 14 additions & 0 deletions securing_sipjs_with_ephemeral_agents/work/public.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAsx00ato/b6svauSZRbBd
ufBmnVC+UYS9lAXr9dFZwqTGmA/bRKfCvqPsfDC2ww+wfNlD8sbL1EvShMtSsbr+
yJpgIFJgTtEHTeo6Cw2uPDutCn6E8JDdEueFngS+adv9i9lH2cnalG8vSyQ49/b3
h1nzBM/F7r4BUxY/bxoz3Ye5FnSkV7ivRJdVSb3iamuLaDFn/qZS3DV8hiGznGAl
h85nsWW/IDi0c6Nhvvwx0zNeLIi7eJujuXjfxzGY/BprZFlp8Jn+Hh8rg3QMVFtd
B04bMCfXE4V2krtVh9tCPzsLYbpxcMd1wdpXIpgDjIBNif0wLtc9WUZHU0Hzox7s
qKnw6fQUWej7b3SS/DXO6uA7wpo80JSVkbrDSGrKY9MLqu3zr9EzHsz/VB49QrIB
k3mlFDkA36QHjJaqnfqa4Ao14tEiMDFftEb63gTP92CuATWElKY5GANQNL8Sol4s
27xW/A+5OgVAVbyWzOmk3x4VKAHkUtvbP8in2daPpgEWdxlerF8dXBtMmt593bRA
sarqcUhCFLtxFFA6BKrxg+lqnOThP+IHB7T9gGncUTCkuBg2sDVhkxmzSWFM+dfm
kTcyY1my4frt7ew8luMiEgi3HOZd0zvXFugFvdQuJv83EkePrV9iJMZwXeeY/a15
45JzSoNCu1UmMmWIQVSTiJcCAwEAAQ==
-----END PUBLIC KEY-----

0 comments on commit ef2cbd1

Please sign in to comment.