📄 netconnection.java
字号:
private void flowEUSRPWDDTAconnect(String password) throws SqlException { flowServerAttributes(); checkSecmgrForSecmecSupport(NetConfiguration.SECMEC_EUSRPWDDTA); initializePublicKeyForEncryption(); flowKeyExchange(NetConfiguration.SECMEC_EUSRPWDDTA, publicKey_); flowSecurityCheckAndAccessRdb(targetSecmec_, //securityMechanism null, //user null, //password encryptedUseridForEUSRIDPWD(), encryptedPasswordForEUSRIDPWD(password)); } private void flowServerAttributes() throws SqlException { agent_.beginWriteChainOutsideUOW(); netAgent_.netConnectionRequest_.writeExchangeServerAttributes(extnam_, //externalName targetAgent_, netAgent_.targetSqlam_, targetRdb_, targetSecmgr_, targetCmntcpip_, targetCmnappc_, targetXamgr_, targetSyncptmgr_, targetRsyncmgr_); agent_.flowOutsideUOW(); netAgent_.netConnectionReply_.readExchangeServerAttributes(this); agent_.endReadChain(); } private void flowKeyExchange(int securityMechanism, byte[] publicKey) throws SqlException { agent_.beginWriteChainOutsideUOW(); netAgent_.netConnectionRequest_.writeAccessSecurity(securityMechanism, databaseName_, publicKey); agent_.flowOutsideUOW(); netAgent_.netConnectionReply_.readAccessSecurity(this, securityMechanism); agent_.endReadChain(); } private void flowServerAttributesAndKeyExchange(int securityMechanism, byte[] publicKey) throws SqlException { agent_.beginWriteChainOutsideUOW(); writeServerAttributesAndKeyExchange(securityMechanism, publicKey); agent_.flowOutsideUOW(); readServerAttributesAndKeyExchange(securityMechanism); agent_.endReadChain(); } private void flowSecurityCheckAndAccessRdb(int securityMechanism, String user, String password, byte[] encryptedUserid, byte[] encryptedPassword) throws SqlException { agent_.beginWriteChainOutsideUOW(); writeSecurityCheckAndAccessRdb(securityMechanism, user, password, encryptedUserid, encryptedPassword); agent_.flowOutsideUOW(); readSecurityCheckAndAccessRdb(); agent_.endReadChain(); } private void writeAllConnectCommandsChained(int securityMechanism, String user, String password) throws SqlException { writeServerAttributesAndKeyExchange(securityMechanism, null); // publicKey writeSecurityCheckAndAccessRdb(securityMechanism, user, password, null, //encryptedUserid null); //encryptedPassword, } private void readAllConnectCommandsChained(int securityMechanism) throws SqlException { readServerAttributesAndKeyExchange(securityMechanism); readSecurityCheckAndAccessRdb(); } private void writeServerAttributesAndKeyExchange(int securityMechanism, byte[] publicKey) throws SqlException { netAgent_.netConnectionRequest_.writeExchangeServerAttributes(extnam_, //externalName targetAgent_, netAgent_.targetSqlam_, targetRdb_, targetSecmgr_, targetCmntcpip_, targetCmnappc_, targetXamgr_, targetSyncptmgr_, targetRsyncmgr_); netAgent_.netConnectionRequest_.writeAccessSecurity(securityMechanism, databaseName_, publicKey); } private void readServerAttributesAndKeyExchange(int securityMechanism) throws SqlException { netAgent_.netConnectionReply_.readExchangeServerAttributes(this); netAgent_.netConnectionReply_.readAccessSecurity(this, securityMechanism); } private void writeSecurityCheckAndAccessRdb(int securityMechanism, String user, String password, byte[] encryptedUserid, byte[] encryptedPassword) throws SqlException { netAgent_.netConnectionRequest_.writeSecurityCheck(securityMechanism, databaseName_, user, password, encryptedUserid, encryptedPassword); netAgent_.netConnectionRequest_.writeAccessDatabase(databaseName_, false, crrtkn_, prddta_, netAgent_.typdef_); } private void cacheConnectBytes(int beginOffset, int endOffset) { int length = endOffset - beginOffset; cachedConnectBytes_ = new byte[length]; netAgent_.netConnectionRequest_.finalizePreviousChainedDss(false); System.arraycopy(netAgent_.netConnectionRequest_.bytes_, beginOffset, cachedConnectBytes_, 0, length); netAgent_.netConnectionRequest_.setDssLengthLocation(netAgent_.netConnectionRequest_.offset_); } private void readSecurityCheckAndAccessRdb() throws SqlException { netAgent_.netConnectionReply_.readSecurityCheck(this); netAgent_.netConnectionReply_.readAccessDatabase(this); } void writeDeferredReset() throws SqlException { if (canUseCachedConnectBytes_ && cachedConnectBytes_ != null && (securityMechanism_ == NetConfiguration.SECMEC_USRIDPWD || securityMechanism_ == NetConfiguration.SECMEC_USRIDONL)) { writeDeferredResetFromCache(); wroteConnectFromCache_ = true; } else { int beginOffset = netAgent_.netConnectionRequest_.offset_; int endOffset = 0; // NetConfiguration.SECMEC_USRIDPWD if (securityMechanism_ == NetConfiguration.SECMEC_USRIDPWD) { writeAllConnectCommandsChained(NetConfiguration.SECMEC_USRIDPWD, user_, getDeferredResetPassword()); endOffset = netAgent_.netConnectionRequest_.offset_; cacheConnectBytes(beginOffset, endOffset); } // NetConfiguration.SECMEC_USRIDONL else if (securityMechanism_ == NetConfiguration.SECMEC_USRIDONL) { writeAllConnectCommandsChained(NetConfiguration.SECMEC_USRIDONL, user_, null); //password endOffset = netAgent_.netConnectionRequest_.offset_; cacheConnectBytes(beginOffset, endOffset); } // either NetConfiguration.SECMEC_USRENCPWD or NetConfiguration.SECMEC_EUSRIDPWD else { initializePublicKeyForEncryption(); // Set the resetConnectionAtFirstSql_ to false to avoid going in an // infinite loop, since all the flow methods call beginWriteChain which then // calls writeDeferredResetConnection where the check for resetConnectionAtFirstSql_ // is done. By setting the resetConnectionAtFirstSql_ to false will avoid calling the // writeDeferredReset method again. resetConnectionAtFirstSql_ = false; flowServerAttributesAndKeyExchange(securityMechanism_, publicKey_); agent_.beginWriteChainOutsideUOW(); // Reset the resetConnectionAtFirstSql_ to true since we are done // with the flow method. resetConnectionAtFirstSql_ = true; // NetConfiguration.SECMEC_USRENCPWD if (securityMechanism_ == NetConfiguration.SECMEC_USRENCPWD) { writeSecurityCheckAndAccessRdb(NetConfiguration.SECMEC_USRENCPWD, user_, null, //password null, //encryptedUserid encryptedPasswordForUSRENCPWD(getDeferredResetPassword())); } // NetConfiguration.SECMEC_EUSRIDPWD else { writeSecurityCheckAndAccessRdb(NetConfiguration.SECMEC_EUSRIDPWD, null, //user null, //password encryptedUseridForEUSRIDPWD(), encryptedPasswordForEUSRIDPWD(getDeferredResetPassword())); } } } } void readDeferredReset() throws SqlException { resetConnectionAtFirstSql_ = false; if (wroteConnectFromCache_) { netAgent_.netConnectionReply_.verifyDeferredReset(); return; } // either NetConfiguration.SECMEC_USRIDPWD or NetConfiguration.SECMEC_USRIDONL if (securityMechanism_ == NetConfiguration.SECMEC_USRIDPWD || securityMechanism_ == NetConfiguration.SECMEC_USRIDONL) { readAllConnectCommandsChained(securityMechanism_); } // either NetConfiguration.SECMEC_USRENCPWD or NetConfiguration.SECMEC_EUSRIDPWD else { // either NetConfiguration.SECMEC_USRENCPWD or NetConfiguration.SECMEC_EUSRIDPWD readSecurityCheckAndAccessRdb(); } if (agent_.loggingEnabled()) { agent_.logWriter_.traceConnectResetExit(this); } } //-------------------parse callback methods-------------------------------- void setServerAttributeData(String extnam, String srvclsnm, String srvnam, String srvrlslv) { targetExtnam_ = extnam; // any of these could be null targetSrvclsnm_ = srvclsnm; // since then can be optionally returned from the targetSrvnam_ = srvnam; // server targetSrvrlslv_ = srvrlslv; } // secmecList is always required and will not be null. // secchkcd has an implied severity of error. // it will be returned if an error is detected. // if no errors and security mechanism requires a sectkn, then void setAccessSecurityData(int secchkcd, int desiredSecmec, int[] secmecList, boolean sectknReceived, byte[] sectkn) throws DisconnectException { // - if the secchkcd is not 0, then map to an exception. if (secchkcd != CodePoint.SECCHKCD_00) { // the implied severity code is error netAgent_.setSvrcod(CodePoint.SVRCOD_ERROR); agent_.accumulateReadException(mapSecchkcd(secchkcd)); } else { // - verify that the secmec parameter reflects the value sent // in the ACCSEC command. // should we check for null list if ((secmecList.length == 1) && (secmecList[0] == desiredSecmec)) { // the security mechanism returned from the server matches // the mechanism requested by the client. targetSecmec_ = secmecList[0]; if ((targetSecmec_ == NetConfiguration.SECMEC_USRENCPWD) || (targetSecmec_ == NetConfiguration.SECMEC_EUSRIDPWD) || (targetSecmec_ == NetConfiguration.SECMEC_EUSRIDDTA) || (targetSecmec_ == NetConfiguration.SECMEC_EUSRPWDDTA)) { // a security token is required for USRENCPWD, or EUSRIDPWD. if (!sectknReceived) { agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_, "secktn was not returned ")); } else { targetPublicKey_ = sectkn; if (encryptionManager_ != null) { encryptionManager_.resetSecurityKeys(); } } } } else { // accumulate an SqlException and don't disconnect yet // if a SECCHK was chained after this it would receive a secchk code // indicating the security mechanism wasn't supported and that would be a // chain breaking exception. if no SECCHK is chained this exception // will be surfaced by endReadChain // agent_.accumulateChainBreakingReadExceptionAndThrow ( // new DisconnectException (agent_,"secmec not supported ","0000", -999)); agent_.accumulateReadException(new SqlException(agent_.logWriter_, "secmec not supported")); } } } void securityCheckComplete(int svrcod, int secchkcd) { netAgent_.setSvrcod(svrcod); if (secchkcd == CodePoint.SECCHKCD_00) { return; } agent_.accumulateReadException(mapSecchkcd(secchkcd)); } void rdbAccessed(int svrcod, String prdid, boolean crrtknReceived, byte[] crrtkn) { if (crrtknReceived) { crrtkn_ = crrtkn; } netAgent_.setSvrcod(svrcod); productID_ = prdid; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -