Esempio n. 1
0
 public KeyConfiguration()
 {
     this.m_KeyAreaEncryptionKeyList = new List <Tuple <int, AesKey> >();
     this.m_KeyAreaEncryptionKeyList.Add(Tuple.Create <int, AesKey>(0, new AesKey(new byte[16]
     {
         (byte)58,
         (byte)124,
         (byte)62,
         (byte)56,
         (byte)74,
         (byte)143,
         (byte)34,
         byte.MaxValue,
         (byte)75,
         (byte)33,
         (byte)87,
         (byte)25,
         (byte)183,
         (byte)129,
         (byte)173,
         (byte)12
     })));
     this.m_NcaHeader1SignKey          = (RsaKey)null;
     this.m_AcidSignKey                = (RsaKey)null;
     this.m_ProdKeyAreaEncryptionKey   = (AesKey)null;
     this.m_ProdNcaHeaderEncryptionKek = (AesKey)null;
     this.m_NrrCertificateSignKey      = (RsaKey)null;
 }
Esempio n. 2
0
        public void SetKey(string keyConfigFilePath)
        {
            XElement xml = XElement.Load(keyConfigFilePath);

            try
            {
                foreach (XElement element in xml.Elements((XName)"KeyAreaEncryptionKeys").Elements <XElement>((XName)"Key"))
                {
                    this.m_KeyAreaEncryptionKeyList.Add(Tuple.Create <int, AesKey>(Convert.ToInt32(element.Attribute((XName)"index").Value), new AesKey(Convert.FromBase64String(element.Value))));
                }
                this.m_ProdKeyAreaEncryptionKey   = KeyConfiguration.LoadAesKeyConfig(xml, "ProdKeyAreaEncryptionKey");
                this.m_ProdNcaHeaderEncryptionKek = KeyConfiguration.LoadAesKeyConfig(xml, "ProdNcaHeaderEncryptionKek");
                this.m_NcaHeader1SignKey          = KeyConfiguration.LoadRsaKeyConfig(xml, "NcaHeader1SignKey");
                this.m_AcidSignKey                     = KeyConfiguration.LoadRsaKeyConfig(xml, "NcaAcidSignKey");
                this.m_NrrCertificateSignKey           = KeyConfiguration.LoadRsaKeyConfig(xml, "NcaNrrCertificateSignKey");
                this.m_ProdXciHeaderSignKey            = KeyConfiguration.LoadRsaKeyConfig(xml, "ProdXciHeaderSignKey");
                this.m_ProdXciInitialDataEncryptionKey = KeyConfiguration.LoadAesKeyConfig(xml, "ProdXciInitialDataEncryptionKey");
                this.m_ProdTitleKeyGenarateKey         = KeyConfiguration.LoadAesKeyConfig(xml, "ProdTitleKeyGenarateKey");
                this.m_ProdETicketCommonKey            = KeyConfiguration.LoadAesKeyConfig(xml, "ProdETicketCommonKey");
                this.m_ProdETicketSignKey              = KeyConfiguration.LoadRsaKeyConfig(xml, "ProdETicketSignKey");
            }
            catch
            {
                throw new ArgumentException(string.Format("Failed to load key configuration from {0}.", (object)keyConfigFilePath));
            }
        }
Esempio n. 3
0
        public byte[] PublishTicket(ulong titleId, bool isProdEncryption, KeyConfiguration keyConfiguration)
        {
            AesKey externalContentKey = ExternalContentKeyGenerator.GetNcaExternalContentKey(!isProdEncryption ? (IHashCalculator) new HmacSha256HashCryptoDriver(HmacSha256KeyIndex.TitleKeyGenarateKey) : (keyConfiguration.GetProdTitleKeyGenarateKey() == null ? (IHashCalculator) new HsmHmacSha256HashCryptoDriver(HmacSha256KeyIndex.TitleKeyGenarateKey) : (IHashCalculator) new HmacSha256HashCryptoDriver(keyConfiguration.GetProdTitleKeyGenarateKey().Key)), titleId);

            Ticket.EncryptTitleKey(!isProdEncryption ? (ICbcModeEncryptor) new Aes128CbcCryptoDriver(Aes128KeyIndex.ETicketCommonKey) : (keyConfiguration.GetProdETicketCommonKey() == null ? (ICbcModeEncryptor) new HsmAes128CbcCryptoDriver(Aes128KeyIndex.ETicketCommonKey) : (ICbcModeEncryptor) new Aes128CbcCryptoDriver(keyConfiguration.GetProdETicketCommonKey().Key)), titleId, externalContentKey);
            ulong deviceId = 0;
            ulong ticketId = 0;

            byte[] rightsId = TicketUtility.CreateRightsId(titleId);
            this.m_TicketDataLength = !isProdEncryption ? (int)TicketPublication.PublishTicket(this.m_TicketData, (uint)this.m_TicketData.Length, externalContentKey.Key, deviceId, ticketId, rightsId, Encoding.ASCII.GetBytes("Root-CA00000004-XS00000020")) : (keyConfiguration.GetProdETicketSignKey() == null ? (int)TicketPublication.PublishTicket(this.m_TicketData, (uint)this.m_TicketData.Length, externalContentKey.Key, deviceId, ticketId, rightsId, Encoding.ASCII.GetBytes("Root-CA00000004-XS00000021")) : (int)TicketPublication.PublishTicket(this.m_TicketData, (uint)this.m_TicketData.Length, externalContentKey.Key, deviceId, ticketId, rightsId, Encoding.ASCII.GetBytes("Root-CA00000004-XS00000020")));
            if (isProdEncryption)
            {
                if (keyConfiguration.GetProdETicketSignKey() != null)
                {
                    RsaKey prodEticketSignKey = keyConfiguration.GetProdETicketSignKey();
                    this.SignTicket((ISigner) new Rsa2048Pkcs1Sha256SignCryptoDriver(prodEticketSignKey.KeyModulus, prodEticketSignKey.KeyPublicExponent, prodEticketSignKey.KeyPrivateExponent));
                }
                else
                {
                    this.SignTicket((ISigner) new HsmRsa2048Pkcs1Sha256SignCryptoDriver(Rsa2048Pkcs1Sha256KeyIndex.ETicket));
                }
            }
            else
            {
                byte[] numArray1 = new byte[Sign.GetModulusSize()];
                Sign.GetModulus_XS00000020(numArray1);
                byte[] numArray2 = new byte[Sign.GetPrivateExponentSize()];
                Sign.GetPrivateExponent_XS00000020(numArray2);
                this.SignTicket((ISigner) new Rsa2048Pkcs1Sha256SignCryptoDriver(numArray1, (byte[])null, numArray2));
            }
            return(this.m_TicketData);
        }
 private void SetCryptor(KeyConfiguration keyConfig)
 {
     this.m_keyAreaEncryptionKeyIvEncryptor = (IEncryptor) new Rsa2048OaepSha256CryptoDriver(Rsa2048OaepSha256KeyIndex.XciKeyArea);
     if (keyConfig.GetProdXciHeaderSignKey() != null)
     {
         RsaKey xciHeaderSignKey = keyConfig.GetProdXciHeaderSignKey();
         this.m_headerSigner = (ISigner) new Rsa2048Pkcs1Sha256SignCryptoDriver(xciHeaderSignKey.KeyModulus, xciHeaderSignKey.KeyPublicExponent, xciHeaderSignKey.KeyPrivateExponent);
     }
     else
     {
         this.m_headerSigner = (ISigner) new HsmRsa2048Pkcs1Sha256SignCryptoDriver(Rsa2048Pkcs1Sha256KeyIndex.XciHeader);
     }
     this.m_initialDataEncryptor = keyConfig.GetProdXciInitialDataEncryptionKey() == null ? (IEncryptor) new HsmAes128CryptoDriver(Aes128KeyIndex.XciInitialData) : (IEncryptor) new Aes128CryptoDriver(keyConfig.GetProdXciInitialDataEncryptionKey().Key);
     this.m_headerEncryptor      = (ICbcModeEncryptor) new Aes128CbcCryptoDriver(Aes128KeyIndex.XciHeader);
 }
Esempio n. 5
0
 private void SetCryptor(KeyConfiguration config)
 {
     if (this.m_fileSystemInfo.isProdEncryption)
     {
         this.m_bodyEncryptionKeyEncryptor = this.m_keyConfig.GetProdKeyAreaEncryptionKey() == null ? (IEncryptor) new HsmAes128CryptoDriver(Aes128KeyIndex.NcaContentKey) : (IEncryptor) new Aes128CryptoDriver(this.m_keyConfig.GetProdKeyAreaEncryptionKey().Key);
         byte[][] numArray1 = new byte[2][]
         {
             new byte[16],
             new byte[16]
         };
         byte[][] numArray2 = new byte[2][]
         {
             new byte[16]
             {
                 (byte)90,
                 (byte)62,
                 (byte)216,
                 (byte)79,
                 (byte)222,
                 (byte)192,
                 (byte)216,
                 (byte)38,
                 (byte)49,
                 (byte)247,
                 (byte)226,
                 (byte)93,
                 (byte)25,
                 (byte)123,
                 (byte)245,
                 (byte)208
             },
             new byte[16]
             {
                 (byte)28,
                 (byte)155,
                 (byte)123,
                 (byte)250,
                 (byte)246,
                 (byte)40,
                 (byte)24,
                 (byte)61,
                 (byte)113,
                 (byte)246,
                 (byte)77,
                 (byte)115,
                 (byte)241,
                 (byte)80,
                 (byte)185,
                 (byte)210
             }
         };
         IEncryptor encryptor = this.m_keyConfig.GetProdNcaHeaderEncryptionKek() == null ? (IEncryptor) new HsmAes128CryptoDriver(Aes128KeyIndex.NcaHeader) : (IEncryptor) new Aes128CryptoDriver(this.m_keyConfig.GetProdNcaHeaderEncryptionKek().Key);
         encryptor.DecryptBlock(numArray2[0], 0, 16, numArray1[0], 0);
         encryptor.DecryptBlock(numArray2[1], 0, 16, numArray1[1], 0);
         this.m_headerEncryptor = (IXtsModeEncryptor) new Aes128XtsCryptoDriver(numArray1[0], numArray1[1]);
         if (this.m_keyConfig.GetNcaHeader1SignKey() != null)
         {
             RsaKey ncaHeader1SignKey = this.m_keyConfig.GetNcaHeader1SignKey();
             this.m_header1Signer = (ISigner) new Rsa2048PssSha256SignCryptoDriver(ncaHeader1SignKey.KeyModulus, ncaHeader1SignKey.KeyPublicExponent, ncaHeader1SignKey.KeyPrivateExponent);
         }
         else
         {
             this.m_header1Signer = (ISigner) new HsmRsa2048PssSha256SignCryptoDriver(Rsa2048PssSha256KeyIndex.NcaHeader1);
         }
         if (this.m_fileSystemInfo.contentType != (byte)0)
         {
             this.m_header2Signer = (ISigner)null;
         }
         else
         {
             RsaKey randomRsaKey = this.m_keyConfig.GetRandomRsaKey();
             this.m_header2Signer = (ISigner) new Rsa2048PssSha256SignCryptoDriver(randomRsaKey.KeyModulus, randomRsaKey.KeyPublicExponent, randomRsaKey.KeyPrivateExponent);
         }
         if (this.m_keyConfig.GetAcidSignKey() != null)
         {
             RsaKey acidSignKey = this.m_keyConfig.GetAcidSignKey();
             this.m_acidSigner = (ISigner) new Rsa2048PssSha256SignCryptoDriver(acidSignKey.KeyModulus, acidSignKey.KeyPublicExponent, acidSignKey.KeyPrivateExponent);
         }
         else
         {
             this.m_acidSigner = (ISigner) new HsmRsa2048PssSha256SignCryptoDriver(Rsa2048PssSha256KeyIndex.Acid);
         }
         RsaKey randomRsaKey1 = this.m_keyConfig.GetRandomRsaKey();
         this.m_nrrSigner = (ISigner) new Rsa2048PssSha256SignCryptoDriver(randomRsaKey1.KeyModulus, randomRsaKey1.KeyPublicExponent, randomRsaKey1.KeyPrivateExponent);
         if (this.m_keyConfig.GetNrrCertificateSignKey() != null)
         {
             RsaKey certificateSignKey = this.m_keyConfig.GetNrrCertificateSignKey();
             this.m_nrrCertificateSigner = (ISigner) new Rsa2048PssSha256SignCryptoDriver(certificateSignKey.KeyModulus, certificateSignKey.KeyPublicExponent, certificateSignKey.KeyPrivateExponent);
         }
         else
         {
             this.m_nrrCertificateSigner = (ISigner) new HsmRsa2048PssSha256SignCryptoDriver(Rsa2048PssSha256KeyIndex.NrrCertificate);
         }
     }
     else
     {
         this.m_bodyEncryptionKeyEncryptor = (IEncryptor) new Aes128CryptoDriver(this.m_keyConfig.GetKeyAreaEncryptionKey((uint)this.m_fileSystemInfo.keyAreaEncryptionKeyIndex).Key);
         this.m_headerEncryptor            = (IXtsModeEncryptor) new Aes128XtsCryptoDriver(Aes128XtsCryptoDriver.GetDefaultKey(2), Aes128XtsCryptoDriver.GetDefaultKey(3));
         this.m_header1Signer        = (ISigner) new Rsa2048PssSha256SignCryptoDriver(Rsa2048PssSha256KeyIndex.NcaHeader1);
         this.m_header2Signer        = this.m_fileSystemInfo.contentType != (byte)0 || this.m_fileSystemInfo.header2SignKeyModulus == null || (this.m_fileSystemInfo.header2SignKeyPublicExponent == null || this.m_fileSystemInfo.header2SignKeyPrivateExponent == null) ? (ISigner)null : (ISigner) new Rsa2048PssSha256SignCryptoDriver(this.m_fileSystemInfo.header2SignKeyModulus, this.m_fileSystemInfo.header2SignKeyPublicExponent, this.m_fileSystemInfo.header2SignKeyPrivateExponent);
         this.m_acidSigner           = (ISigner)null;
         this.m_nrrSigner            = (ISigner) new Rsa2048PssSha256SignCryptoDriver(Rsa2048PssSha256KeyIndex.NrrCertificate);
         this.m_nrrCertificateSigner = (ISigner) new Rsa2048PssSha256SignCryptoDriver(Rsa2048PssSha256KeyIndex.NrrCertificate);
     }
 }