Exemple #1
0
  public boolean checkStreamH(
      XStorage xParentStorage,
      String sPath,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes) {
    // open substream element first
    XStream xSubStream = null;
    try {
      XHierarchicalStorageAccess xHStorage =
          (XHierarchicalStorageAccess)
              UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xParentStorage);
      if (xHStorage == null) {
        Error("The storage does not support hierarchical access!");
        return false;
      }

      Object oSubStream = xHStorage.openStreamElementByHierarchicalName(sPath, ElementModes.READ);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open substream '" + sPath + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't open substream '" + sPath + "', exception : " + e + "!");
      return false;
    }

    boolean bResult = InternalCheckStream(xSubStream, sPath, sMediaType, bCompressed, pBytes, true);

    // free the stream resources, garbage collector may remove the object too late
    if (!disposeStream(xSubStream, sPath)) return false;

    return bResult;
  }
Exemple #2
0
  public boolean WriteBytesToEncrStreamH(
      XStorage xStorage,
      String sStreamPath,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes,
      String sPass,
      boolean bCommit) {
    // open substream element
    XStream xSubStream = null;
    try {
      XHierarchicalStorageAccess xHStorage =
          (XHierarchicalStorageAccess)
              UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage);
      if (xHStorage == null) {
        Error("The storage does not support hierarchical access!");
        return false;
      }

      Object oSubStream =
          xHStorage.openEncryptedStreamElementByHierarchicalName(
              sStreamPath, ElementModes.WRITE, sPass);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't create substream '" + sStreamPath + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't create substream '" + sStreamPath + "', exception : " + e + "!");
      return false;
    }

    if (!WriteBytesToStream(xSubStream, sStreamPath, sMediaType, bCompressed, pBytes)) return false;

    XTransactedObject xTransact =
        (XTransactedObject) UnoRuntime.queryInterface(XTransactedObject.class, xSubStream);
    if (xTransact == null) {
      Error("Substream '" + sStreamPath + "', stream opened for writing must be transacted!");
      return false;
    }

    if (bCommit) {
      try {
        xTransact.commit();
      } catch (Exception e) {
        Error(
            "Can't commit storage after substream '"
                + sStreamPath
                + "' change, exception : "
                + e
                + "!");
        return false;
      }
    }

    // free the stream resources, garbage collector may remove the object too late
    if (!disposeStream(xSubStream, sStreamPath)) return false;

    return true;
  }
Exemple #3
0
  public boolean cantOpenStreamH(XStorage xStorage, String sPath, int nMode) {
    // try to open the substream with specified mode must fail

    XHierarchicalStorageAccess xHStorage =
        (XHierarchicalStorageAccess)
            UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage);
    if (xHStorage == null) {
      Error("The storage does not support hierarchical access!");
      return false;
    }

    try {
      Object oDummyStream = xHStorage.openStreamElementByHierarchicalName(sPath, nMode);
      Error("The trying to open substream '" + sPath + "' must fail!");
    } catch (Exception e) {
      return true;
    }

    return false;
  }
Exemple #4
0
  public boolean checkEncrStreamH(
      XStorage xParentStorage, String sPath, String sMediaType, byte[] pBytes, String sPass) {
    // Important: a common password for any of parent storage should not be set or
    //            should be different from sPass
    XHierarchicalStorageAccess xHStorage =
        (XHierarchicalStorageAccess)
            UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xParentStorage);
    if (xHStorage == null) {
      Error("The storage does not support hierarchical access!");
      return false;
    }

    try {
      Object oSubStream = xHStorage.openStreamElementByHierarchicalName(sPath, ElementModes.READ);
      XStream xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      Error("Encrypted substream '" + sPath + "' was opened without password!");
      return false;
    } catch (WrongPasswordException wpe) {
    } catch (Exception e) {
      Error(
          "Unexpected exception in case of opening of encrypted stream '"
              + sPath
              + "' without password: "******"!");
      return false;
    }

    String sWrongPass = "******";
    sWrongPass += sPass;
    try {
      Object oSubStream =
          xHStorage.openEncryptedStreamElementByHierarchicalName(
              sPath, ElementModes.READ, sWrongPass);
      XStream xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      Error("Encrypted substream '" + sPath + "' was opened with wrong password!");
      return false;
    } catch (WrongPasswordException wpe) {
    } catch (Exception e) {
      Error(
          "Unexpected exception in case of opening of encrypted stream '"
              + sPath
              + "' with wrong password: "******"!");
      return false;
    }

    XStream xSubStream = null;
    try {
      Object oSubStream =
          xHStorage.openEncryptedStreamElementByHierarchicalName(sPath, ElementModes.READ, sPass);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open encrypted substream '" + sPath + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't open encrypted substream '" + sPath + "', exception : " + e + "!");
      return false;
    }

    // encrypted streams will be compressed always, so after the storing this property is always
    // true,
    // although before the storing it can be set to false ( it is not always clear whether a stream
    // is encrypted
    // before the storing )
    boolean bResult = InternalCheckStream(xSubStream, sPath, sMediaType, true, pBytes, false);

    // free the stream resources, garbage collector may remove the object too late
    if (!disposeStream(xSubStream, sPath)) return false;

    return bResult;
  }
Exemple #5
0
  public int ChangeStreamPassH(
      XStorage xStorage, String sPath, String sOldPass, String sNewPass, boolean bCommit) {
    // open substream element
    XHierarchicalStorageAccess xHStorage =
        (XHierarchicalStorageAccess)
            UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage);
    if (xHStorage == null) {
      Error("The storage does not support hierarchical access!");
      return 0;
    }

    XStream xSubStream = null;
    try {
      Object oSubStream =
          xHStorage.openEncryptedStreamElementByHierarchicalName(
              sPath, ElementModes.WRITE, sOldPass);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open encrypted substream '" + sPath + "'!");
        return 0;
      }
    } catch (Exception e) {
      Error("Can't open encrypted substream '" + sPath + "', exception : " + e + "!");
      return 0;
    }

    // change the password for the stream
    XEncryptionProtectedSource xStreamEncryption =
        (XEncryptionProtectedSource)
            UnoRuntime.queryInterface(XEncryptionProtectedSource.class, xSubStream);

    if (xStreamEncryption == null) {
      Message(
          "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!");
      return -1;
    }

    try {
      xStreamEncryption.setEncryptionPassword(sNewPass);
    } catch (Exception e) {
      Error("Can't change encryption key of the substream '" + sPath + "', exception:" + e);
      return 0;
    }

    XTransactedObject xTransact =
        (XTransactedObject) UnoRuntime.queryInterface(XTransactedObject.class, xSubStream);
    if (xTransact == null) {
      Error("Substream '" + sPath + "', stream opened for writing must be transacted!");
      return 0;
    }

    if (bCommit) {
      try {
        xTransact.commit();
      } catch (Exception e) {
        Error(
            "Can't commit storage after substream '" + sPath + "' change, exception : " + e + "!");
        return 0;
      }
    }

    // free the stream resources, garbage collector may remove the object too late
    if (!disposeStream(xSubStream, sPath)) return 0;

    return 1;
  }
Exemple #6
0
  public boolean WBToSubstrOfEncrH(
      XStorage xStorage,
      String sStreamPath,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes,
      boolean bEncrypted,
      boolean bCommit) {
    // open substream element
    XStream xSubStream = null;
    try {
      XHierarchicalStorageAccess xHStorage =
          (XHierarchicalStorageAccess)
              UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage);
      if (xHStorage == null) {
        Error("The storage does not support hierarchical access!");
        return false;
      }

      Object oSubStream =
          xHStorage.openStreamElementByHierarchicalName(sStreamPath, ElementModes.WRITE);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't create substream '" + sStreamPath + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't create substream '" + sStreamPath + "', exception : " + e + "!");
      return false;
    }

    // get access to the XPropertySet interface
    XPropertySet xPropSet =
        (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xSubStream);
    if (xPropSet == null) {
      Error("Can't get XPropertySet implementation from substream '" + sStreamPath + "'!");
      return false;
    }

    // set properties to the stream
    try {
      xPropSet.setPropertyValue("UseCommonStoragePasswordEncryption", new Boolean(bEncrypted));
    } catch (Exception e) {
      Error(
          "Can't set 'UseCommonStoragePasswordEncryption' property to substream '"
              + sStreamPath
              + "', exception: "
              + e);
      return false;
    }

    if (!WriteBytesToStream(xSubStream, sStreamPath, sMediaType, bCompressed, pBytes)) return false;

    XTransactedObject xTransact =
        (XTransactedObject) UnoRuntime.queryInterface(XTransactedObject.class, xSubStream);
    if (xTransact == null) {
      Error("Substream '" + sStreamPath + "', stream opened for writing must be transacted!");
      return false;
    }

    if (bCommit) {
      try {
        xTransact.commit();
      } catch (Exception e) {
        Error(
            "Can't commit storage after substream '"
                + sStreamPath
                + "' change, exception : "
                + e
                + "!");
        return false;
      }
    }

    // free the stream resources, garbage collector may remove the object too late
    if (!disposeStream(xSubStream, sStreamPath)) return false;

    return true;
  }