public void open() throws GPException, CardException, IOException {
		if (sdAID == null) {
			// Try known SD AIDs
			// FIXME: use an ordered list instead of unordered entrySet	
			short sw = 0;
			for (Map.Entry<String, AID> entry : AID.SD_AIDS.entrySet()) {
				CommandAPDU command = new CommandAPDU(ISO7816.CLA_ISO7816, ISO7816.INS_SELECT, 0x04, 0x00, entry.getValue().getBytes());
				ResponseAPDU resp = channel.transmit(command);
				sw = (short) resp.getSW();
				if (sw == ISO7816.SW_NO_ERROR) {
					sdAID = entry.getValue();
					System.err.println("Selected Security Domain " + entry.getKey() + " " + entry.getValue().toString());
					break;
				} else if (sw != 0x6A82) {
					System.err.println("Failed to select SD " + entry.getValue().toString() + ", SW: " + GPUtils.swToString(sw));
				}
			}
			if (sdAID == null) {
				throw new GPException(sw, "Could not select any of the known Security Domains!");
			}
		} else {
			CommandAPDU command = new CommandAPDU(ISO7816.CLA_ISO7816, ISO7816.INS_SELECT, 0x04, 0x00, sdAID.getBytes());
			ResponseAPDU resp = channel.transmit(command);
			short sw = (short) resp.getSW();
			if (sw != ISO7816.SW_NO_ERROR) {
				throw new GPException(sw, "Could not select custom sdAID " + sdAID);
			}
		}
	}