Upgrade to Pro — share decks privately, control downloads, hide ads and more …

webinar 03 - deepstream security concepts and f...

webinar 03 - deepstream security concepts and features

This slidedeck was presented for the third webinar by deepstream. It talks about the main security aspects within deepstream.

Avatar for Srushtika Neelakantam

Srushtika Neelakantam

September 12, 2017
Tweet

More Decks by Srushtika Neelakantam

Other Decks in Technology

Transcript

  1. # SSL default configuration (no SSL/TLS) sslKey: //link to sslKey

    sslCert: //link to sslCert sslCa: //null if self generated SSL configuration - required prior to using wss on deepstreamIO
  2. - Nginx - HAProxy - Apache - Most J2EE servers

    like Tomcat and JBoss - AWS Elastic Load Balancing
  3. # Username as key johndoe: password: uY2zMQZXcFuWKeX/6eY43w==9wSp046KHAQfbvKcKgvwNA== clientData: renderColor: brown

    serverData: role: admin samjones: password: 7KZrUQcnFUDNOQtqtKqhCA==ElDieSHdI2vtiws41JF/HQ== clientData: favoriteDessert: shortbread serverData: role: user an example of a user file
  4. file based authentication auth: type: file options: # Path to

    the user file. Can be json, js or yml path: ./users.yml # the name of a HMAC digest algorithm hash: 'md5' # the number of times the algorithm should be applied iterations: 100 # the length of the resulting key keyLength: 32
  5. email authentication client.login({ email: '[email protected]', password: '.......' }, (success, data)

    => { console.log(success, data.token, clientData) // "success": true, // "token": "aI2wYSh1FS_2WODD14bYZe1TfIyhAukl", // "clientData": { // "renderColor": "brown", // "id": "s64907sdkjdsif" // } })
  6. using deepstream’s HTTP API curl -X POST -H "Content-Type: application/json"

    -d '{ "body": [ { "type": "email", "email": "[email protected]", "password": "**********" } ] }'"https://api.deepstreamhub.com/api/v1/user-auth/signup/:apiKey"
  7. session tokens example //retrieve a token from the localStorage const

    token = localStorage.getItem('deepstream-token') //if it is not null, if (token) { //token exists but not validated yet //attempt to resume the previous session using this token resumeSession(token) } else { //logging in for the first time loginWithEmail() } 1
  8. session tokens example function resumeSession (token) { //try logging in

    with session token client.login({ token: token }, function(success, data) { if (success) { onSuccessfulLogin(data) } else { //login failed means the token has expired loginWithEmail() } }) } 2
  9. session tokens example function loginWithEmail () { var myEmail =

    prompt("Enter email", ""); var myPass = prompt("Enter your password", ""); client.login({ email: myEmail, password: myPass }, function(success, data) { if (success) { //replace the token in localStorage with new one localStorage.setItem('deepstream-token', data.token) onSuccessfulLogin(data) } else { // user login failed } }) } 3
  10. client.login({ type: 'webhook', //other custom auth params }, (success, data)

    => { console.log(success, data) { //application logic } }) webhook authentication
  11. //initialize express server app.post('/login', (req, res) => { if (req.body.authData.email

    === '[email protected]' && req.body.authData.password === 'password') { res.json({ userId: '838dc811-75a1-4d71-ba8c-6f8742c6301e', clientData: { renderColor: 'blue' }, serverData: { role: 'admin' } }) } else { res.status(403).end() } }) //set default port a simple express server
  12. event: "*": publish: false subscribe: true user-status/$userId: #users can only

    share their own status publish: "user.id === $userId" what, why and how of valve !
  13. type action record event rpc presence create write read delete

    publish subscribe provide request allow
  14. how? deepstream client const systemSettings = ds.record.getRecord( ‘system-settings’ ) systemSettings.set(

    ‘max-file-storage’, ‘20GB’) deepstream - permissions file(IO) / dashboard(Hub) record: system-settings: write: “user.data.role===’admin’”
  15. variables 1. user { isAuthenticated //true, id //'fdmng34-jn3j45b', data //{

    'role': 'admin', 'accessLevel':3 } } record: companydata: read: “user.data.accessLevel > 2” const cData = client.record.getRecord(‘companydata’)
  16. variables 2. data permissions event: addVerifiedMark: emit: "data.pageLikes > 50"

    deepstream client //const myPagelikes = num of likes on the page client.event.emit(‘addVerifiedMark’, { “pageLikes”: myPagelikes })
  17. variables 3. oldData permissions record: auction/*: write: "data.currentBid > oldData.currentBid"

    deepstream client //current record data {“currentBid” : 20} client.record.setData(‘auction/54’,{ “currentBid”: 50 })
  18. variables 4. now deepstream client //const time =desired time in

    ms client.record.setData(‘dhl/berlin’,{ ‘deliveryTime’: time }) permissions record: dhl/berlin: write: "data.deliveryTime > now"
  19. string functions within Valve - startsWith - endsWith - indexOf

    - match - toUpperCase - toLowerCase - trim
  20. string functions within Valve rpc: book-purchase: request: "data.card.issuer!=null && data.card.issuer.toLowerCase()

    === 'visa'" - startsWith - endsWith - indexOf - match - toUpperCase - toLowerCase - trim
  21. record: car-sale/*: # when booking a new car sale, make

    sure that # the car that's sold exists and that its price # is the same or lower than what the customer is charged write: "_(data.carId) !== null && _(data.carId).price <= data.price" simple cross-referencing
  22. client.rpc.make(‘addComment’, ‘some-comment’, response => { //add comment some-comment }) how

    powerful is cross-referencing? rpc: addComment: request: “_(‘permission/’+user.id).canComment===true” 2