本站源代码
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

53 lignes
1.6KB

  1. package jwt
  2. // Implements the none signing method. This is required by the spec
  3. // but you probably should never use it.
  4. var SigningMethodNone *signingMethodNone
  5. const UnsafeAllowNoneSignatureType unsafeNoneMagicConstant = "none signing method allowed"
  6. var NoneSignatureTypeDisallowedError error
  7. type signingMethodNone struct{}
  8. type unsafeNoneMagicConstant string
  9. func init() {
  10. SigningMethodNone = &signingMethodNone{}
  11. NoneSignatureTypeDisallowedError = NewValidationError("'none' signature type is not allowed", ValidationErrorSignatureInvalid)
  12. RegisterSigningMethod(SigningMethodNone.Alg(), func() SigningMethod {
  13. return SigningMethodNone
  14. })
  15. }
  16. func (m *signingMethodNone) Alg() string {
  17. return "none"
  18. }
  19. // Only allow 'none' alg type if UnsafeAllowNoneSignatureType is specified as the key
  20. func (m *signingMethodNone) Verify(signingString, signature string, key interface{}) (err error) {
  21. // Key must be UnsafeAllowNoneSignatureType to prevent accidentally
  22. // accepting 'none' signing method
  23. if _, ok := key.(unsafeNoneMagicConstant); !ok {
  24. return NoneSignatureTypeDisallowedError
  25. }
  26. // If signing method is none, signature must be an empty string
  27. if signature != "" {
  28. return NewValidationError(
  29. "'none' signing method with non-empty signature",
  30. ValidationErrorSignatureInvalid,
  31. )
  32. }
  33. // Accept 'none' signing method.
  34. return nil
  35. }
  36. // Only allow 'none' signing if UnsafeAllowNoneSignatureType is specified as the key
  37. func (m *signingMethodNone) Sign(signingString string, key interface{}) (string, error) {
  38. if _, ok := key.(unsafeNoneMagicConstant); ok {
  39. return "", nil
  40. }
  41. return "", NoneSignatureTypeDisallowedError
  42. }
上海开阖软件有限公司 沪ICP备12045867号-1