Example #1
0
            public void Read(RecordInputStream in1)
            {
                _encryptionInfo = in1.ReadUShort();
                switch (_encryptionInfo)
                {
                case ENCRYPTION_OTHER_RC4:
                    // handled below
                    break;

                case ENCRYPTION_OTHER_CAPI_2:
                case ENCRYPTION_OTHER_CAPI_3:
                case ENCRYPTION_OTHER_CAPI_4:
                    throw new EncryptedDocumentException(
                              "HSSF does not currently support CryptoAPI encryption");

                default:
                    throw new RecordFormatException("Unknown encryption info " + _encryptionInfo);
                }
                _minorVersionNo = in1.ReadUShort();
                if (_minorVersionNo != 1)
                {
                    throw new RecordFormatException("Unexpected VersionInfo number for RC4Header " + _minorVersionNo);
                }
                _salt = FilePassRecord.Read(in1, 16);
                _encryptedVerifier     = FilePassRecord.Read(in1, 16);
                _encryptedVerifierHash = FilePassRecord.Read(in1, 16);
            }
Example #2
0
            public RecordInputStream CreateDecryptingStream(Stream original)
            {
                FilePassRecord fpr          = _filePassRec;
                String         userPassword = Biff8EncryptionKey.CurrentUserPassword;

                if (userPassword == null)
                {
                    userPassword = Decryptor.DEFAULT_PASSWORD;
                }

                //return new RecordInputStream(original, key, _InitialRecordsSize);
                throw new NotImplementedException("Implement it based on poi 4.2 in the future");
            }
Example #3
0
            public StreamEncryptionInfo(RecordInputStream rs, List <Record> outputRecs)
            {
                Record rec;

                rs.NextRecord();
                int recSize = 4 + rs.Remaining;

                rec = RecordFactory.CreateSingleRecord(rs);
                outputRecs.Add(rec);
                FilePassRecord fpr = null;

                if (rec is BOFRecord)
                {
                    _hasBOFRecord = true;
                    if (rs.HasNextRecord)
                    {
                        rs.NextRecord();
                        rec      = RecordFactory.CreateSingleRecord(rs);
                        recSize += rec.RecordSize;
                        outputRecs.Add(rec);
                        if (rec is FilePassRecord)
                        {
                            fpr = (FilePassRecord)rec;
                            outputRecs.RemoveAt(outputRecs.Count - 1);
                            // TODO - add fpr not Added to outPutRecs
                            rec = outputRecs[0];
                        }
                        else
                        {
                            // workbook not encrypted (typical case)
                            if (rec is EOFRecord)
                            {
                                // A workbook stream is never empty, so crash instead
                                // of trying to keep track of nesting level
                                throw new InvalidOperationException("Nothing between BOF and EOF");
                            }
                        }
                    }
                }
                else
                {
                    // Invalid in a normal workbook stream.
                    // However, some test cases work on sub-sections of
                    // the workbook stream that do not begin with BOF
                    _hasBOFRecord = false;
                }
                _InitialRecordsSize = recSize;
                _filePassRec        = fpr;
                _lastRecord         = rec;
            }
Example #4
0
            public RecordInputStream CreateDecryptingStream(Stream original)
            {
                FilePassRecord fpr          = _filePassRec;
                String         userPassword = Biff8EncryptionKey.CurrentUserPassword;

                Biff8EncryptionKey key;

                if (userPassword == null)
                {
                    key = Biff8EncryptionKey.Create(fpr.DocId);
                }
                else
                {
                    key = Biff8EncryptionKey.Create(userPassword, fpr.DocId);
                }
                if (!key.Validate(fpr.SaltData, fpr.SaltHash))
                {
                    throw new EncryptedDocumentException(
                              (userPassword == null ? "Default" : "Supplied")
                              + " password is invalid for docId/saltData/saltHash");
                }
                return(new RecordInputStream(original, key, _InitialRecordsSize));
            }
Example #5
0
 public override Object Clone()
 {
     FilePassRecord rec = new FilePassRecord();
     rec.field_1_encryptedpassword = field_1_encryptedpassword;
     return rec;
 }
Example #6
0
			public StreamEncryptionInfo(RecordInputStream rs, List<Record> outputRecs)
			{
				Record rec;
				rs.NextRecord();
				int recSize = 4 + rs.Remaining;
				rec = RecordFactory.CreateSingleRecord(rs);
				outputRecs.Add(rec);
				FilePassRecord fpr = null;
				if (rec is BOFRecord)
				{
					_hasBOFRecord = true;
					// Fetch the next record, and see if it indicates whether
					//  the document is encrypted or not
					if (rs.HasNextRecord)
					{
						rs.NextRecord();
						rec = RecordFactory.CreateSingleRecord(rs);
						recSize += rec.RecordSize;
						outputRecs.Add(rec);
						// Encrypted is normally BOF then FILEPASS
						// May sometimes be BOF, WRITEPROTECT, FILEPASS
						if (rec is WriteProtectRecord && rs.HasNextRecord)
						{
							rs.NextRecord();
							rec = RecordFactory.CreateSingleRecord(rs);
							recSize += rec.RecordSize;
							outputRecs.Add(rec);
						}
						// If it's a FILEPASS, track it specifically but
						//  don't include it in the main stream
						if (rec is FilePassRecord)
						{
							fpr = (FilePassRecord)rec;
							outputRecs.RemoveAt(outputRecs.Count - 1);
							// TODO - add fpr not Added to outPutRecs
							rec = outputRecs[0];
						}
						else
						{
							// workbook not encrypted (typical case)
							if (rec is EOFRecord)
							{
								// A workbook stream is never empty, so crash instead
								// of trying to keep track of nesting level
								throw new InvalidOperationException("Nothing between BOF and EOF");
							}
						}
					}
				}
				else
				{
					// Invalid in a normal workbook stream.
					// However, some test cases work on sub-sections of
					// the workbook stream that do not begin with BOF
					_hasBOFRecord = false;
				}
				_InitialRecordsSize = recSize;
				_filePassRec = fpr;
				_lastRecord = rec;
			}
 public StreamEncryptionInfo(RecordInputStream rs, List<Record> outputRecs)
 {
     Record rec;
     rs.NextRecord();
     int recSize = 4 + rs.Remaining;
     rec = RecordFactory.CreateSingleRecord(rs);
     outputRecs.Add(rec);
     FilePassRecord fpr = null;
     if (rec is BOFRecord)
     {
         _hasBOFRecord = true;
         if (rs.HasNextRecord)
         {
             rs.NextRecord();
             rec = RecordFactory.CreateSingleRecord(rs);
             recSize += rec.RecordSize;
             outputRecs.Add(rec);
             if (rec is FilePassRecord)
             {
                 fpr = (FilePassRecord)rec;
                 outputRecs.RemoveAt(outputRecs.Count - 1);
                 // TODO - add fpr not Added to outPutRecs
                 rec = outputRecs[0];
             }
             else
             {
                 // workbook not encrypted (typical case)
                 if (rec is EOFRecord)
                 {
                     // A workbook stream is never empty, so crash instead
                     // of trying to keep track of nesting level
                     throw new InvalidOperationException("Nothing between BOF and EOF");
                 }
             }
         }
     }
     else
     {
         // Invalid in a normal workbook stream.
         // However, some test cases work on sub-sections of
         // the workbook stream that do not begin with BOF
         _hasBOFRecord = false;
     }
     _InitialRecordsSize = recSize;
     _filePassRec = fpr;
     _lastRecord = rec;
 }
            public StreamEncryptionInfo(RecordInputStream rs, List <Record> outputRecs)
            {
                Record rec;

                rs.NextRecord();
                int recSize = 4 + rs.Remaining;

                rec = RecordFactory.CreateSingleRecord(rs);
                outputRecs.Add(rec);
                FilePassRecord fpr = null;

                if (rec is BOFRecord)
                {
                    _hasBOFRecord = true;
                    // Fetch the next record, and see if it indicates whether
                    //  the document is encrypted or not
                    if (rs.HasNextRecord)
                    {
                        rs.NextRecord();
                        rec      = RecordFactory.CreateSingleRecord(rs);
                        recSize += rec.RecordSize;
                        outputRecs.Add(rec);
                        // Encrypted is normally BOF then FILEPASS
                        // May sometimes be BOF, WRITEPROTECT, FILEPASS
                        if (rec is WriteProtectRecord && rs.HasNextRecord)
                        {
                            rs.NextRecord();
                            rec      = RecordFactory.CreateSingleRecord(rs);
                            recSize += rec.RecordSize;
                            outputRecs.Add(rec);
                        }
                        // If it's a FILEPASS, track it specifically but
                        //  don't include it in the main stream
                        if (rec is FilePassRecord)
                        {
                            fpr = (FilePassRecord)rec;
                            outputRecs.RemoveAt(outputRecs.Count - 1);
                            // TODO - add fpr not Added to outPutRecs
                            rec = outputRecs[0];
                        }
                        else
                        {
                            // workbook not encrypted (typical case)
                            if (rec is EOFRecord)
                            {
                                // A workbook stream is never empty, so crash instead
                                // of trying to keep track of nesting level
                                throw new InvalidOperationException("Nothing between BOF and EOF");
                            }
                        }
                    }
                }
                else
                {
                    // Invalid in a normal workbook stream.
                    // However, some test cases work on sub-sections of
                    // the workbook stream that do not begin with BOF
                    _hasBOFRecord = false;
                }
                _InitialRecordsSize = recSize;
                _filePassRec        = fpr;
                _lastRecord         = rec;
            }
Example #9
0
 private FilePassRecord(FilePassRecord other)
 {
     _encryptionType = other._encryptionType;
     _keyData        = (KeyData)other._keyData.Clone();
 }