GithubHelp home page GithubHelp logo

kjur / jsjws Goto Github PK

View Code? Open in Web Editor NEW
227.0 227.0 47.0 1.4 MB

(IMPORTANT NOTICE: END OF SUPPORT! jsjws have been merged into http://kjur.github.io/jsrsasign/. So please move to jsrsasign. The 'jsjws' is a pure JavaScript implementation of JSON Web Signature(JWS) and JSON Web Token(JWT).

Home Page: http://kjur.github.io/jsjws/

License: Other

HTML 68.56% JavaScript 30.69% CSS 0.74%

jsjws's People

Contributors

davedoesdev avatar kjur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsjws's Issues

ReferenceError: sHead is not defined

Hi. You have a mistake in jws 3.1. sHead variable does not exist.

KJUR.jws.JWS.sign = function(alg, sHeader, sPayload, key, pass) {
    var ns1 = KJUR.jws.JWS;

    if (! ns1.isSafeJSONString(sHeader))
    throw "JWS Head is not safe JSON string: " + sHead;

Can someone please explain to me how the user agent's pvk remains a secret?

I haven't dug into this implementation yet because failure to retain secrecy of the remote client's private key material would be a non-starter for my particular use case and I'm curious to know if this is worth looking into further.

How in the world would you process the private key without loading it into the browser and therefore make it accessible to anyone eavesdropping in that browser's Dev Tools, thereby making the client's private key public knowledge to anyone with access to their browser?

Actual Security

Sorry for my ignorant question. But assuming I buld at HTML page using JSON/JSJWS. The values I want to encrypt are in the JSON, in the HTML.

So, I then encrypt before sending, so great, http traffic is encrypted. But, if someone looked at html source, wouldn't they see original values?

Error in sign function

Hi,
in both files (full and min) in version 3.0 there is an error:

KJUR.jws.JWS.sign = function(alg, sHeader, sPayload, key, pass) {
    var ns1 = KJUR.jws.JWS;

    if (! ns1.isSafeJSONString(sHeader))
    throw "JWS Head is not safe JSON string: " + sHead;

the "sHead" should be "sHeader", the same goes to min file there should be "p" instead of "sHead"

Signatures not valid on HS256

Generate the default value from http://kjur.github.io/jsjws/tool_jwt.html:

Without a signature it generates:
eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTQxNTEwNDAxOSwiZXhwIjoxNDE1MTA3NjE5LCJpYXQiOjE0MTUxMDQwMTksImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciJ9.

It self validates fine.... and at jwt.io.

Changing to hmac256 with the defaults does not seem to be signed correctly when pasted into jwt.io.

I haven't tried further, in case I'm doing something else wrong in the process. If you can confirm this should function, I'll start looking at the code for the source of the issue.

[enhancement] Add missing bower.json.

Hey, maintainer(s) of kjur/jsjws!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library kjur/jsjws is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "kjur/jsjws",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Tests are failing

Hello, I have cloned this repo and am trying to run the unit tests locally. The following files contain failing unit tests:

  • qunit-do-jws-sign.html
  • qunit-do-jws-intdate.html

These tests fail on the latest Chrome, Firefox and Safari.

readSafeJSONString returns null

This code for decoding a token is directly taken from the demo on the website:

  var a = currentToken.split(".");
  var uHeader = b64utos(a[0]);
  var uClaim = b64utos(a[1]);
  var pHeader = KJUR.jws.JWS.readSafeJSONString(uHeader);
  var pClaim = KJUR.jws.JWS.readSafeJSONString(uClaim);

Problem here is that readSafeJSONString always returns null for a valid json (checked in json lint). I am using it with

  'vendor/jsrsasign/jsrsasign-4.1.4-all-min.js',
  'vendor/jsjws/jws-3.0.min.js'

Any ideas?

this.isSafeJSONString is not a function

Using you library and trying to verify a signed token using

    var sJWS = "the token"
    var sPemX509Cert = "-----BEGIN CERTIFICATE----- etc"
    var jws = new KJUR.jws.JWS();
    var result = jws.verifyJWSByPemX509Cert(sJWS, sPemX509Cert);

The console throws the following error:

TypeError: this.isSafeJSONString is not a function
    at parseJWS (http://localhost:8100/lib/jsjws/jws-3.2.js:115:13)
    at verifyJWSByPemX509Cert (http://localhost:8100/lib/jsjws/jws-3.2.js:203:7)
    ...

I solved creating the mentioned function (from your source code, jws-3.2.js):

    //variables
    var jws = new KJUR.jws.JWS();
    jws.isSafeJSONString = function(s, h, p) {
        var o = null;
        try {
        o = jsonParse(s);
        if (typeof o != "object") return 0;
        if (o.constructor === Array) return 0;
        if (h) h[p] = o;
        return 1;
        } catch (ex) {
        return 0;
        }
    };
    var result = jws.verifyJWSByPemX509Cert(sJWS, sPemX509Cert);

Error in sign function "JWS Head is not safe JSON string"

My header string is being passed as:

'{"alg": "HS256", "cty": "JWT"}'

which is pasted directly from one of the jsjws tests, AND validates just fine in JSONlint and every other parser I have found, What is meant by "safe" JSON string in this instance?

Strict mode problem

asn1x509-1.0.js defines subjectKeyIdentifier twice which produces the following warning in Node:

Warning: asn1x509-1.0.js:1810
        'subjectKeyIdentifier': '2.5.29.14',
        ^^^^^^^^^^^^^^^^^^^^^^
Duplicate data property in object literal not allowed in strict mode Use --force to continue.

Removing one of the occurrences fixes it.

Update kjur.github.io demos to use jws-3.0.js

The demos don't use jws 3.0 so for example ES384 seems to not work.

I'm also getting a

Error: TypeError: Cannot read property 'bitLength' of undefined

when using the demo with one of the ES384 test vectors. The library should be more robust against these kinds of errors. The test vectors:

https://github.com/kjur/jsjws/blob/master/test/qunit-do-jws-sign.html#L394

-----BEGIN PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEVDUmq9/Ec5Sj8mRbDUhlGp86TUbYdAvj
IpFRB/BQJQxzDKQLN+HcheCCtLsYG4hHvW0Poni65escBUdMmk4r7sKMlwvknBlJ
8J6Wl5onelFIMOMqW53h7GirmfSS3TAK
-----END PUBLIC KEY-----

and

eyJhbGciOiJFUzM4NCIsICJjdHkiOiJKV1QifQ.eyJhZ2UiOiAyMX0.ImFmrFvzlyl-BGHz8sdD6we6T1uCL5d6Q-oCWmDSh-q8eSL1bxPix7XZjxZGYJySw1On974Vw2NmzffgXvDPk7Ayvau0_fp0v4KUh4x6RcGKZDQgXVli1mfrGKTFP37C

Enhance documentation

This looks like it's exactly what I need, but there seems to be almost no documentation. There's the API docs, sure, but nothing else. Readme is barebone, and the tutorials link directs to an empty wiki. I tried reading the code on the site, but either I have version or dependency issues.

Some questions:

  • What dependencies are required?
  • What is the relation between jsjws and jsrasign? jsjws seems to depend on jsrasign, but why it then the former included in the install of the latter?
  • Basic working examples would be nice, for a recent version. The stuff I got from the demos page seems outdated, or at least didn't work for me.
  • Basically a how-to is missing
  • What's the difference of readSafeJSONString wrt JSON.parse?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.