APNCertificate.js 831 B

123456789101112131415161718192021222324252627282930313233
  1. const APNKey = require('./APNKey');
  2. const oids = require('./oids');
  3. function APNCertificate(cert) {
  4. if (!cert.publicKey || !cert.validity || !cert.subject) {
  5. throw new Error('certificate object is invalid');
  6. }
  7. this._cert = cert;
  8. }
  9. APNCertificate.prototype.key = function () {
  10. return new APNKey(this._cert.publicKey);
  11. };
  12. APNCertificate.prototype.validity = function () {
  13. return this._cert.validity;
  14. };
  15. APNCertificate.prototype.environment = function () {
  16. const environment = { sandbox: false, production: false };
  17. if (this._cert.getExtension({ id: oids.applePushServiceClientDevelopment })) {
  18. environment.sandbox = true;
  19. }
  20. if (this._cert.getExtension({ id: oids.applePushServiceClientProduction })) {
  21. environment.production = true;
  22. }
  23. return environment;
  24. };
  25. module.exports = APNCertificate;