cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a procedure/function as hidden in one step?

VolkerBarth
Contributor
3,967

Say, I have a function whose contents should be hidden. The general way to create such a function needs two steps:

:::SQL
create function myFunction() returns varchar(255) 
begin
   return 'SomethingNearlySecret';
end;

alter function myFunction
set hidden;

After the second step, the function's original definition is obfuscated and cannot be queried from the system tables.

However, the current transaction log contains both statements and therefore still has the definition available. The same would be available when the statements will be distributed by SQL Remote's passthrough mode, and the remote would run in verbose mode.

Is there a way to create a hidden function (or procedure, trigger or view) in one step, not leaving the original definition in the log file?

(Note: I'm aware that this is just obfuscation and not strong encryption.)

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

A valid solution seems to be the following, even across different SA versions:

  1. Create the function as documented in two steps - but in a different database, not in the original database. Possibly create that database just for this purpose.
  2. Unload the function's definition from that particular database, say by DBUNLOAD -n.
  3. The reload.sql file will contain a create function statement with the undocumented CREATE ... HIDDEN syntax, something like

    create function myOwner.myFunction hidden '(()(()**...$';

  4. This particular statement can be run against the original database and will create the hidden definition without leaving the original statement in the log.

This seems to work with ASA 8.0.3 and SA 12.0.1 though I'm not sure whether the hidden definition is truly version-independent.

VolkerBarth
Contributor
0 Kudos

Just a remark: The hidden definition does also contain information about the function's parameters and return type. This is still available in system table sysprocparm - for obvious reasons: Otherwise, the function would not be usable anymore IMHO...

VolkerBarth
Contributor
0 Kudos

To the iAnywhere experts:

Is my assumption that this approach will work over different versions (at least v8 - v12) correct?

Answers (1)

Answers (1)

Breck_Carter
Participant

Another workaround (or enhancement, depending on your point of view) might be to store the critical core text of the procedure in a LONG VARCHAR column in a CREATE TABLE ... ENCRYPTED, and run it with EXECUTE IMMEDIATE.

Kludgy yes, but encryption beats obfuscation.

Breck

VolkerBarth
Contributor

Do you suggest to store in a table/column with DBA-only access? Otherwise, the table encryption wouldn't protect against querying that table, only against database file inspection.

And in case the column contents itself should be enctrypted, then the according encryption key must be stored anywhere else, lifting the encryption/obfuscation discussion to the next level:)

Besides that, an interesting suggestion, for sure.

VolkerBarth
Contributor
0 Kudos

Oh well, I'm too good at obfuscating, should have written "encrypted" instead of "enctrypted". One of my key problems:)

I think we can all decipher your meaning.