Android Open Source - steamchat Asn Key Parser






From Project

Back to project page steamchat.

License

The source code is released under:

Apache License

If you think the Android project steamchat listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kevelbreh.steamchat.steam.security;
//from   ww  w .  j ava2  s . c  o m
import java.math.BigInteger;
import java.util.List;

/**
 * Created by kevin on 2014/08/12.
 */
public class AsnKeyParser {

    final AsnParser _parser;

  /*public AsnKeyParser(String pathname) {
    using (var reader = new BinaryReader(
      new FileStream(pathname, FileMode.Open, FileAccess.Read)))
    {
      var info = new FileInfo(pathname);

      _parser = new AsnParser(reader.ReadBytes((int)info.Length));
    }
  }*/

    public AsnKeyParser(List<Byte> contents) {
        _parser = new AsnParser(contents);
    }

    public static byte[] trimLeadingZero(byte[] values) {
        byte[] r;
        if (0x00 == values[0] && values.length > 1) {
            r = new byte[values.length - 1];
            System.arraycopy(values, 1, r, 0, values.length - 1);
        } else {
            r = new byte[values.length];
            System.arraycopy(values, 0, r, 0, values.length);
        }

        return r;
    }

    public static boolean equalOid(byte[] first, byte[] second) {
        if (first.length != second.length) {
            return false;
        }

        for (int i = 0; i < first.length; i++) {
            if (first[i] != second[i]) {
                return false;
            }
        }

        return true;
    }

    public BigInteger[] parseRSAPublicKey() throws BerDecodeException {
        final BigInteger[] parameters = new BigInteger[2];

        // Current value

        // Sanity Check

        // Checkpoint
        int position = _parser.currentPosition();

        // Ignore Sequence - PublicKeyInfo
        int length = _parser.nextSequence();
        if (length != _parser.remainingBytes()) {
            final StringBuilder sb = new StringBuilder("Incorrect Sequence Size. ");
            sb.append(String.format("Specified: %d, Remaining: %d", length, _parser.remainingBytes()));
            throw new BerDecodeException(sb.toString(), position);
        }

        // Checkpoint
        position = _parser.currentPosition();

        // Ignore Sequence - AlgorithmIdentifier
        length = _parser.nextSequence();
        if (length > _parser.remainingBytes()) {
            final StringBuilder sb = new StringBuilder("Incorrect AlgorithmIdentifier Size. ");
            sb.append(String.format("Specified: %d, Remaining: %d", length, _parser.remainingBytes()));
            throw new BerDecodeException(sb.toString(), position);
        }

        // Checkpoint
        position = _parser.currentPosition();
        // Grab the OID
        final byte[] value = _parser.nextOID();
        final byte[] oid = { (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x01 };
        if (!AsnKeyParser.equalOid(value, oid)) {
            throw new BerDecodeException("Expected OID 1.2.840.113549.1.1.1", position);
        }

        // Optional Parameters
        if (_parser.IsNextNull()) {
            _parser.NextNull();
            // Also OK: value = _parser.Next();
        } else {
            // Gracefully skip the optional data
            _parser.Next();
        }

        // Checkpoint
        position = _parser.currentPosition();

        // Ignore BitString - PublicKey
        length = _parser.NextBitString();
        if (length > _parser.remainingBytes()) {
            final StringBuilder sb = new StringBuilder("Incorrect PublicKey Size. ");
            sb.append(String.format("Specified: %d, Remaining: %d", length, _parser.remainingBytes()));
            throw new BerDecodeException(sb.toString(), position);
        }

        // Checkpoint
        position = _parser.currentPosition();

        // Ignore Sequence - RSAPublicKey
        length = _parser.nextSequence();
        if (length < _parser.remainingBytes()) {
            final StringBuilder sb = new StringBuilder("Incorrect RSAPublicKey Size. ");
            sb.append(String.format("Specified: %d, Remaining: %d", length, _parser.remainingBytes()));
            throw new BerDecodeException(sb.toString(), position);
        }

        parameters[0] = new BigInteger(1, AsnKeyParser.trimLeadingZero(_parser.nextInteger()));
        parameters[1] = new BigInteger(1, AsnKeyParser.trimLeadingZero(_parser.nextInteger()));

        return parameters;
    }
}




Java Source Code List

com.kevelbreh.steamchat.SteamChat.java
com.kevelbreh.steamchat.account.AuthenticatorService.java
com.kevelbreh.steamchat.account.Authenticator.java
com.kevelbreh.steamchat.account.SteamAccount.java
com.kevelbreh.steamchat.activity.AuthenticationActivity.java
com.kevelbreh.steamchat.activity.ConversationActivity.java
com.kevelbreh.steamchat.activity.FriendsActivity.java
com.kevelbreh.steamchat.activity.InteractionsActivity.java
com.kevelbreh.steamchat.activity.LauncherActivity.java
com.kevelbreh.steamchat.activity.SettingsActivity.java
com.kevelbreh.steamchat.fragment.ConversationFragment.java
com.kevelbreh.steamchat.fragment.FriendsFragment.java
com.kevelbreh.steamchat.fragment.InteractionsFragment.java
com.kevelbreh.steamchat.fragment.SettingsFragment.java
com.kevelbreh.steamchat.provider.SteamProviderUtils.java
com.kevelbreh.steamchat.provider.SteamProvider.java
com.kevelbreh.steamchat.provider.content.InteractionContentItem.java
com.kevelbreh.steamchat.provider.content.PersonaContentItem.java
com.kevelbreh.steamchat.provider.content.UserContentItem.java
com.kevelbreh.steamchat.steam2.SteamConnection.java
com.kevelbreh.steamchat.steam2.SteamEventBus.java
com.kevelbreh.steamchat.steam2.SteamService.java
com.kevelbreh.steamchat.steam2.handler.ConnectionHandler.java
com.kevelbreh.steamchat.steam2.handler.FriendHandler.java
com.kevelbreh.steamchat.steam2.handler.MessageHandler.java
com.kevelbreh.steamchat.steam2.handler.UserHandler.java
com.kevelbreh.steamchat.steam2.packet.Packet.java
com.kevelbreh.steamchat.steam2.packet.ProtoPacket.java
com.kevelbreh.steamchat.steam.SteamClient.java
com.kevelbreh.steamchat.steam.SteamID.java
com.kevelbreh.steamchat.steam.SteamServiceHandler.java
com.kevelbreh.steamchat.steam.SteamService.java
com.kevelbreh.steamchat.steam.handler2.ConnectionHandler.java
com.kevelbreh.steamchat.steam.handler2.FriendHandler.java
com.kevelbreh.steamchat.steam.handler2.Handler.java
com.kevelbreh.steamchat.steam.handler2.UserHandler.java
com.kevelbreh.steamchat.steam.handler.AEventHandler.java
com.kevelbreh.steamchat.steam.handler.AuthenticationHandler.java
com.kevelbreh.steamchat.steam.handler.FriendsHandler.java
com.kevelbreh.steamchat.steam.handler.IEventHandler.java
com.kevelbreh.steamchat.steam.handler.IHandler.java
com.kevelbreh.steamchat.steam.handler.MessageDebugHandler.java
com.kevelbreh.steamchat.steam.language.Language.java
com.kevelbreh.steamchat.steam.language.Message.java
com.kevelbreh.steamchat.steam.network.TCPConnection.java
com.kevelbreh.steamchat.steam.network.packet.ChannelEncryptRequest.java
com.kevelbreh.steamchat.steam.network.packet.ChannelEncryptResponse.java
com.kevelbreh.steamchat.steam.network.packet.ChannelEncryptResult.java
com.kevelbreh.steamchat.steam.network.packet.ClientLogOnResponse.java
com.kevelbreh.steamchat.steam.network.packet.ClientLogOn.java
com.kevelbreh.steamchat.steam.network.packet.HeartBeat.java
com.kevelbreh.steamchat.steam.network.packet.MultiPacket.java
com.kevelbreh.steamchat.steam.network.packet.Packet.java
com.kevelbreh.steamchat.steam.network.packet.ProtoPacket.java
com.kevelbreh.steamchat.steam.proto.DescriptorsProto.java
com.kevelbreh.steamchat.steam.proto.EncryptedAppTicketProto.java
com.kevelbreh.steamchat.steam.proto.SteamMessagesBaseProto.java
com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.java
com.kevelbreh.steamchat.steam.security.AsnKeyParser.java
com.kevelbreh.steamchat.steam.security.AsnParser.java
com.kevelbreh.steamchat.steam.security.BerDecodeException.java
com.kevelbreh.steamchat.steam.security.Cryptography.java
com.kevelbreh.steamchat.steam.security.NetEncryption.java
com.kevelbreh.steamchat.steam.security.PublicKey.java
com.kevelbreh.steamchat.steam.security.RSA.java
com.kevelbreh.steamchat.steam.util.BinaryReader.java
com.kevelbreh.steamchat.steam.util.BinaryWriter.java
com.kevelbreh.steamchat.steam.util.BitVector64.java
com.kevelbreh.steamchat.steam.util.JenkinsHash.java
com.kevelbreh.steamchat.util.AServiceActivity.java
com.kevelbreh.steamchat.util.Dump.java
com.kevelbreh.steamchat.util.MiscUtils.java
com.kevelbreh.steamchat.widget.adapter.ChatAdapter.java
com.kevelbreh.steamchat.widget.adapter.ConversationAdapter.java
com.kevelbreh.steamchat.widget.adapter.FriendAdapter.java
com.kevelbreh.steamchat.widget.view.AvatarView.java
com.kevelbreh.steamchat.widget.view.FriendInteractionsView.java