📄 reply.java
字号:
shiftSize += 2; } // it is a syntax error if the dss continuation is less than or equal to two if (continueHeaderLength <= 2) { doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_CONT_LESS_OR_EQUAL_2); } newDssLength += (continueHeaderLength - 2); // calculate the number of bytes to shift if (i != (continueDssHeaderCount - 1)) { bytesToShift = 32767; } else { bytesToShift = dssLength_; } tempPos -= (shiftSize - 1); // perform the compress for (int j = 0; j < bytesToShift; j++) { buffer_[tempPos + shiftSize] = buffer_[tempPos]; tempPos--; } tempPos += (shiftSize + 1); } // reposition the start of the data after the final dss shift. pos_ = tempPos; dssLength_ = dssLength_ + newDssLength; } protected final void readDssHeader() throws org.apache.derby.client.am.DisconnectException { int correlationID = 0; int nextCorrelationID = 0; ensureALayerDataInBuffer(6); // read out the dss length dssLength_ = ((buffer_[pos_++] & 0xFF) << 8) + ((buffer_[pos_++] & 0xFF) << 0); // Remember the old dss length for decryption only. int oldDssLength = dssLength_; // check for the continuation bit and update length as needed. if ((dssLength_ & 0x8000) == 0x8000) { dssLength_ = 32767; dssIsContinued_ = true; } else { dssIsContinued_ = false; } if (dssLength_ < 6) { doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_LESS_THAN_6); } // If the GDS id is not valid, or // if the reply is not an RPYDSS nor // a OBJDSS, then throw an exception. if ((buffer_[pos_++] & 0xFF) != 0xd0) { doSyntaxrmSemantics(CodePoint.SYNERRCD_CBYTE_NOT_D0); } int gdsFormatter = buffer_[pos_++] & 0xFF; if (((gdsFormatter & 0x02) != 0x02) && ((gdsFormatter & 0x03) != 0x03) && ((gdsFormatter & 0x04) != 0x04)) { doSyntaxrmSemantics(CodePoint.SYNERRCD_FBYTE_NOT_SUPPORTED); } // Determine if the current DSS is chained with the // next DSS, with the same or different request ID. if ((gdsFormatter & 0x40) == 0x40) { // on indicates structure chained to next structure if ((gdsFormatter & 0x10) == 0x10) { dssIsChainedWithSameID_ = true; dssIsChainedWithDiffID_ = false; nextCorrelationID = dssCorrelationID_; } else { dssIsChainedWithSameID_ = false; dssIsChainedWithDiffID_ = true; nextCorrelationID = dssCorrelationID_ + 1; } } else { // chaining bit not b'1', make sure DSSFMT bit3 not b'1' if ((gdsFormatter & 0x10) == 0x10) { // Next DSS can not have same correlator doSyntaxrmSemantics(CodePoint.SYNERRCD_CHAIN_OFF_SAME_NEXT_CORRELATOR); } // chaining bit not b'1', make sure no error continuation if ((gdsFormatter & 0x20) == 0x20) { // must be 'do not continue on error' doSyntaxrmSemantics(CodePoint.SYNERRCD_CHAIN_OFF_ERROR_CONTINUE); } dssIsChainedWithSameID_ = false; dssIsChainedWithDiffID_ = false; nextCorrelationID = 1; } correlationID = ((buffer_[pos_++] & 0xFF) << 8) + ((buffer_[pos_++] & 0xFF) << 0); // corrid must be the one expected or a -1 which gets returned in some error cases. if ((correlationID != dssCorrelationID_) && (correlationID != 0xFFFF)) { doSyntaxrmSemantics(CodePoint.SYNERRCD_INVALID_CORRELATOR); } else { dssCorrelationID_ = nextCorrelationID; } dssLength_ -= 6; if ((gdsFormatter & 0x04) == 0x04) { decryptData(gdsFormatter, oldDssLength); //we have to decrypt data here because } //we need the decrypted codepoint. If //Data is very long > 32767, we have to //get all the data first because decrypt //piece by piece doesn't work. } private final void decryptData(int gdsFormatter, int oldDssLength) throws org.apache.derby.client.am.DisconnectException { boolean readHeader; if (dssLength_ == 32761) { ByteArrayOutputStream baos; int copySize = 0; baos = new ByteArrayOutputStream(); // set the amount to read for the first segment copySize = dssLength_; // note: has already been adjusted for headers do { // determine if a continuation header needs to be read after the data if (dssIsContinued_) { readHeader = true; } else { readHeader = false; } // read the segment ensureALayerDataInBuffer(copySize); adjustLengths(copySize); baos.write(buffer_, pos_, copySize); pos_ += copySize; // read the continuation header, if necessary if (readHeader) { readDSSContinuationHeader(); } copySize = dssLength_; } while (readHeader == true); byte[] cipherBytes = baos.toByteArray(); byte[] clearedByte = null; try { clearedByte = netAgent_.netConnection_.getEncryptionManager().decryptData(cipherBytes, NetConfiguration.SECMEC_EUSRIDPWD, netAgent_.netConnection_.getTargetPublicKey(), netAgent_.netConnection_.getTargetPublicKey()); } catch (SqlException e) { //throw new SqlException (agent_.logWriter_, "error in decrypting data"); } //The decrypted data is for one codepoint only. We need to save the data follows this codepoint longBufferForDecryption_ = new byte[buffer_.length - pos_]; longPosForDecryption_ = 0; count_ = count_ - pos_; longCountForDecryption_ = count_; System.arraycopy(buffer_, pos_, longBufferForDecryption_, 0, buffer_.length - pos_); //copy the clear data to buffer_ if (clearedByte.length >= 32767) { System.arraycopy(clearedByte, 0, buffer_, 0, 32767); } else { System.arraycopy(clearedByte, 0, buffer_, 0, clearedByte.length); } pos_ = 0; dssLength_ = buffer_.length; int lobLength = 0; if (clearedByte.length > 32767) { //for extended length, length is the 4 bytes that follow codepoint lobLength = ((clearedByte[4] & 0xFF) << 24) + ((clearedByte[5] & 0xFF) << 16) + ((clearedByte[6] & 0xFF) << 8) + ((clearedByte[7] & 0xFF) << 0); longValueForDecryption_ = new byte[lobLength]; System.arraycopy(clearedByte, 8, longValueForDecryption_, 0, clearedByte.length - 8); } else { lobLength = ((clearedByte[0] & 0xFF) << 8) + ((clearedByte[1] & 0xFF) << 0); longValueForDecryption_ = new byte[lobLength - 4]; System.arraycopy(clearedByte, 4, longValueForDecryption_, 0, clearedByte.length - 4); } } else { int bytesRead = ensureALayerDataInBuffer(dssLength_); //we need to get back all the data here, and then decrypt if (bytesRead > 0) //we ensuredALayerDAtaInBuffer here and set the flag to true, so we don't need do this again later { ensuredLengthForDecryption_ = true; } byte[] encryptedByte = new byte[dssLength_]; System.arraycopy(buffer_, pos_, encryptedByte, 0, dssLength_); byte[] array1 = new byte[pos_]; System.arraycopy(buffer_, 0, array1, 0, pos_); //save the data before encrypted data in array1 byte[] array3 = new byte[buffer_.length - dssLength_ - pos_]; System.arraycopy(buffer_, pos_ + dssLength_, array3, 0, buffer_.length - dssLength_ - pos_); //save the data follows encrypted data in array3 byte[] clearedByte = null; try { clearedByte = netAgent_.netConnection_.getEncryptionManager().decryptData(encryptedByte, NetConfiguration.SECMEC_EUSRIDPWD, netAgent_.netConnection_.getTargetPublicKey(), netAgent_.netConnection_.getTargetPublicKey()); } catch (SqlException e) { //throw new SqlException (agent_.logWriter_, "error in decrypting data"); } dssLength_ -= (encryptedByte.length - clearedByte.length); byte[] buffer = new byte[array1.length + clearedByte.length + array3.length]; System.arraycopy(array1, 0, buffer, 0, array1.length); System.arraycopy(clearedByte, 0, buffer, array1.length, clearedByte.length); System.arraycopy(array3, 0, buffer, array1.length + clearedByte.length, array3.length); buffer_ = buffer; int oldCount = count_; count_ = count_ - (encryptedByte.length - clearedByte.length); if (((clearedByte[2] & 0xff) << 8) + ((clearedByte[3] & 0xff) << 0) == 0x146c) { int firstLobLength = ((clearedByte[0] & 0xFF) << 8) + ((clearedByte[1] & 0xFF) << 0); boolean flag = false; if (gdsFormatter == 0x54) { flag = true; } if (flag) { if (oldCount - oldDssLength < 6) { int totalBytesRead = fill(6); //sometimes the 2nd EXTDTA doesn't come back, need to fetch again to get it if (totalBytesRead > 0) { longBufferForDecryption_ = new byte[totalBytesRead]; longPosForDecryption_ = 0; System.arraycopy(buffer_, pos_ + firstLobLength, longBufferForDecryption_, 0, totalBytesRead); } } else { longBufferForDecryption_ = new byte[count_ - pos_ - firstLobLength]; longPosForDecryption_ = 0; System.arraycopy(buffer_, pos_ + firstLobLength, longBufferForDecryption_, 0, longBufferForDecryption_.length); } } //end if(flag) int lobLength = ((clearedByte[0] & 0xFF) << 8) + ((clearedByte[1] & 0xFF) << 0) - 4; longValueForDecryption_ = new byte[lobLength]; System.arraycopy(clearedByte, 4, longValueForDecryption_, 0, clearedByte.length - 4); //copy the decrypted lob value (excluded length an dcodepoint) to longValue_ } else if (((clearedByte[2] & 0xff) << 8) + ((clearedByte[3] & 0xff) << 0) == 0x241B) { int length = ((clearedByte[0] & 0xFF) << 8) + ((clearedByte[1] & 0xFF) << 0); boolean noData = false; if (clearedByte[4] == -1 && clearedByte[5] == -1) { noData = true; //there is no data, no need to do the copy } if (!noData) { if (length == 32776) { length = ((clearedByte[4] & 0xFF) << 24) + ((clearedByte[5] & 0xFF) << 16) + ((clearedByte[6] & 0xFF) << 8) + ((clearedByte[7] & 0xFF) << 0); longValueForDecryption_ = new byte[length]; System.arraycopy(clearedByte, 8, longValueForDecryption_, 0, clearedByte.length - 8); longCountForDecryption_ = count_ - (pos_ + length + 8); longBufferForDecryption_ = new byte[buffer_.length - pos_ - length - 8]; System.arraycopy(buffer_, pos_ + length + 8, longBufferForDecryption_, 0, longBufferForDecryption_.length); } else { longPosForDecryption_ = 0; longCountForDecryption_ = count_ - (pos_ + length); longBufferForDecryption_ = new byte[buffer_.length - pos_ - length]; System.arraycopy(buffer_, pos_ + length, longBufferForDecryption_, 0, longBufferForDecryption_.length); longValueForDecryption_ = new byte[length - 4]; System.arraycopy(clearedByte, 4, longValueForDecryption_, 0,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -