Search in sources :

Example 1 with ClumpletReader

use of org.firebirdsql.gds.ClumpletReader in project jaybird by FirebirdSQL.

the class WireConnection method addServerKeys.

void addServerKeys(byte[] serverKeys) throws SQLException {
    final ClumpletReader newKeys = new ClumpletReader(ClumpletReader.Kind.UnTagged, serverKeys);
    for (newKeys.rewind(); !newKeys.isEof(); newKeys.moveNext()) {
        if (newKeys.getClumpTag() == TAG_KNOWN_PLUGINS) {
            continue;
        }
        int currentTag = newKeys.getClumpTag();
        if (currentTag != TAG_KEY_TYPE) {
            throw new SQLException("Unexpected tag type: " + currentTag);
        }
        String keyType = newKeys.getString(StandardCharsets.US_ASCII);
        newKeys.moveNext();
        if (newKeys.isEof()) {
            break;
        }
        currentTag = newKeys.getClumpTag();
        if (currentTag != TAG_KEY_PLUGINS) {
            throw new SQLException("Unexpected tag type: " + currentTag);
        }
        String keyPlugins = newKeys.getString(StandardCharsets.US_ASCII);
        knownServerKeys.add(new KnownServerKey(keyType, keyPlugins));
    }
}
Also used : KnownServerKey(org.firebirdsql.gds.ng.wire.crypt.KnownServerKey) SQLException(java.sql.SQLException) ClumpletReader(org.firebirdsql.gds.ClumpletReader)

Example 2 with ClumpletReader

use of org.firebirdsql.gds.ClumpletReader in project jaybird by FirebirdSQL.

the class ClientAuthBlock method resetClient.

public void resetClient(byte[] serverInfo) throws SQLException {
    if (serverInfo != null) {
        if (currentPlugin != null && currentPlugin.hasServerData()) {
            // We should not change plugins iterator now
            return;
        }
        ClumpletReader serverList = new ClumpletReader(ClumpletReader.Kind.UnTagged, serverInfo);
        if (serverList.find(TAG_KNOWN_PLUGINS)) {
            String serverPluginNames = serverList.getString(StandardCharsets.US_ASCII);
            serverPlugins.clear();
            serverPlugins.addAll(splitPluginList(serverPluginNames));
        }
    }
    firstTime = true;
    currentPlugin = null;
    pluginProviders = getSupportedPluginProviders();
    if (!serverPlugins.isEmpty()) {
        List<AuthenticationPluginSpi> mergedProviderList = new ArrayList<>();
        for (AuthenticationPluginSpi clientProvider : pluginProviders) {
            if (serverPlugins.contains(clientProvider.getPluginName())) {
                mergedProviderList.add(clientProvider);
            }
        }
        if (mergedProviderList.isEmpty()) {
            throw new FbExceptionBuilder().exception(ISCConstants.isc_login).exception(ISCConstants.isc_random).messageParameter("No matching plugins on server").toFlatSQLException();
        }
        pluginProviders = mergedProviderList;
    }
}
Also used : FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) ClumpletReader(org.firebirdsql.gds.ClumpletReader)

Aggregations

ClumpletReader (org.firebirdsql.gds.ClumpletReader)2 SQLException (java.sql.SQLException)1 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)1 KnownServerKey (org.firebirdsql.gds.ng.wire.crypt.KnownServerKey)1