分类 Security 中的文章

Oauth2.0

what is oauth2.0 OAuth 2.0, which stands for “Open Authorization”, is a standard designed to allow a website or application to access resources hosted by other web apps on behalf of a user. It replaced OAuth 1.0 in 2012 and is now the d industry standard for online authorization. OAuth 2.0 provides consented access and restricts actions of what the client app can perform on resources on behalf of the user, without ever sharing the user’s credentials.……

阅读全文

JWT

what is jwt JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties. jwt structure A well-formed JWT consists of three concatenated Base64url-encoded strings, separated by dots (.): JOSE Header: contains metadata about the type of token and the cryptographic algorithms used to secure its contents. JWS payload (set of claims): contains verifiable security statements, such as the identity of the user and the permissions they are allowed.……

阅读全文

JWT、JWE、JWS 、JWK 到底是什么

什么是 JWT 一个JWT,应该是如下形式的: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9. TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ JWT 解决什么问题? JWT的主要目的是在服务端和客户端之间以安全的方式来转移声明。主要的应用场景如下所示: 认证 Authentication; 授权 Authorization // 注意这两个单词的区别; 联合识别; 客户端会话(无状态的会话); 客户端机密。 JWT 的一些名词解释 JWS:Signed JWT签名过的jwt JWE:Encrypted JWT部分payload经过加密的jwt;目前加密payload的操作不是很普及; JWK:JWT的密钥,也就是我们常说的 scret; JWKset:JWT key set在非对称加密中,需要的是密钥对而非单独的密钥,在后文中会阐释; JWA:当前JWT所用到的密码学算法; nonsecure JWT:当头部的签名算法被设定为none的时候,该JWT是不安全的;因为签名的部分空缺,所有人都可以修改。 ### JWT的组成 一个通常你看到的jwt,由以下三部分组成,它们分别是: header:主要声明了JWT的签名算法; payload:主要承载了各种声明并传递明文数据; signture:拥有该部分的JWT被称为JWS,也就是签了名的JWS;没有该部分的JWT被称为nonsecure JWT 也就是不安全的JWT,此时header中声明的签名算法为none。 三个部分用·分割。形如 xxxxx.yyyyy.zzzzz的样式。 JWT header { “typ”: “JWT”, “alg”: “none”, “jti”: “4f1g23a12aa” } jwt header 的组成 头通常由两部分组成:令牌的类型,即JWT,以及正在使用的散列算法,例如HMAC SHA256或RSA。 当然,还有两个可选的部分,一个是jti,也就是JWT ID,代表了正在使用JWT的编号,这个编号在对应服务端应当唯一。当然,jti也可以放在payload中。 另一个是cty,也就是content type。这个比较少见,当payload为任意数据的时候,这个头无需设置,但是当内容也带有jwt的时候。也就是嵌套JWT的时候,这个值必须设定为jwt。这种情况比较少见。 jwt header 的加密算法 加密的方式如下: base64UrlEncode(header) >> eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIiwianRpIjoiNGYxZzIzYTEyYWEifQ JWT payload {……

阅读全文